'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\web\GroupUrlRule',
'prefix' => 'user',
'rules' => [
# Url Path # Path to controller
'registration/' => 'FAKE DATA',
'password-recovery/',
],
]
],
It seems my routes ‘registration/' and 'password-recovery/' are not determined by path to controller but only by the url path. As you can see on the first one I put 'FAKE DATA' and on the second one I didn't put anything at all.
I don't even understand how the routes can be working.
How can I specify a path to controller route in this case ?
EDIT: in fact, the entire 'rules' section is ignored. Not sure why.
Afaik, the GroupUrlRule is only used to simplify the rules sharing the same prefix in their patterns and routes. If you have these rules,
[
'class' => 'yii\web\GroupUrlRule',
'prefix' => 'user',
'rules' => [
# Url Path # Path to controller
'registration/' => 'fake', //there should be actionFake on UserController
'password-recovery/' => '',
],
]
URL user/registration will hit the actionFake on UserController. Showing the content of your UserController could be useful.
Related
I have an app where I want my user to be able to add their own SMTP server, whether by Mailgun, Amazon SES, etc.
If we're taking the mailgun as an example, right now my Mailgun is set up in config/web.php like so
'mailgun' => [
'class' => 'boundstate\mailgun\Mailer',
'key' => 'MYKEY',
'domain' => 'DOMAIN',
],
Then I use the following to compose an email
Yii::$app->mailgun->compose()->setFrom($FROM)
->setReplyTo($contest_creator_email)
->setTo($email)
->setSubject($subject_line)
->setTextBody($plaintext)
->setHtmlBody($htmlemail)
->send();
How would I make it so that my user could set-up his own key instead of using mine? Is there a way to do this?
You can do this by setting mailer configuration.
Before sending email you can set mailer configuration in your api/controller.
//Set config value dynamicaly
Yii::$app->set('mailer', [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'YourHostName',
'username' => 'UserName',
'password' => 'Password',
'port' => 'Port',
'encryption' => 'Encryption'
],
]);
And send mail as below.
Yii::$app->mailer->compose()->setFrom($FROM)
->setReplyTo($contest_creator_email)
->setTo($email)
->setSubject($subject_line)
->setTextBody($plaintext)
->setHtmlBody($htmlemail)
->send();
I can properly upload files to my s3 bucket using fedemotta yii2-aws-sdk extension. I cannot access the files because I have to set access rights to each file I upload.
My config looks something like this:
'components' => [
'awssdk' => [
'class' => 'fedemotta\awssdk\AwsSdk',
'credentials' => [
'key' => 'ZXCV',
'secret' => 'zxcv',
],
'region' => 'us-east-1',
'version' => 'latest',
],
I found out that in the default yii2-file-upload extension, it can be done using setACL('public-read'). How do I do this in fedemotta extension?
Solved.
Just add 'ACL' => 'public-read', to your upload function in the model
$this->s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filepath,
'ACL' => 'public-read',
));`
So using yii I want to have urls like this:
mydomain.com/some-short-slug
And this url to map the following:
mydomain.com/book?bookslug=some-short-slug
How can I do this?
You need do this inside url-manager:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
'rules' => array(
...
'<slug>'=>'book/index'
...
),
Now, if url like mydomain.com/some-short-slug, you have $slug equal to "some-short-slug" in the actionIndex of BookController
I'm trying to use this extension in a partial view, in my registration module...
$form->widget('ext.tokenInput.TokenInput', array(
'model' => $model,
'attribute' => 'tags',
'url' => array('wizard/search'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
'allowFreeTagging' => false,
'minChars' => 2,
'theme' => 'facebook',
)
));
...and assets (javascript and CSS files) are duplicated.
Basically I can see in the HTML code multiple occurrences of these files.
I have the same problem if I try to add custom JS files in the same partial view.
I specify POS_HEAD and I can see the code in <head> and in the middle of the page.
Why CClientScript duplicates assets if I add them in a partial view?
Thanks a lot!
I have url: /profile/profileBase/index where "profile" is module, "profileBase" is controller and "index" is action.
I want to url manager would accept route like: /profile/read/index
where "read" could be alias of controller.
Is there any way to do this using url manager rules?
Thanks
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'profile/read/index '=>'profile/profileBase/index'
),
),
You should simply add the following rule in urlManager config :
'profile/read/index'=>'profile/profileBase/index',