could you, please, advise,
['label' => 'Dashboard', 'url' => ['']],
how to set "url" to the url kind of "http://example.com"?
I mean how to set this to the url, which is outside of Yii baseurl.
thanks
It's simple.
In this way you can
['label' => 'Dashboard', 'url' => 'http://example.com']
Related
I have this raw in my view.php file:
[
'attribute' => 'Descrizione',
'format' => 'html',
'value' => function ( $model ) {
return nl2br($model->Descrizione);
},
'label' => 'Descrizione',
],
What I want is to hide the entire field if the value don't contains any character, so if is = "" OR is NULL. So I want to hide the entire field "Descrizione".
Which is the option that I have to add in this code?
Thank you very much
You can use the options attribute to set a CSS style.
for example:
empty($model->Descrizione)?'hidden':''
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activefield
Eg:
<?= $form->field($model, 'Descrizione',['options'=>['class'=>empty($model->Descrizione)?'hidden':'']])->textInput(['maxlength' => true, 'disabled' => true]) ?>
Make sure the class "hidden" is actually defined - if you are using bootstrap you can use d-none
Are you using Gridview or DetailView ?
If DetailView, try :
[
'attribute' => 'Descrizione',
'label' => 'Descrizione',
'visible' => !empty($model->Descrizione),
'format' => 'ntext',
],
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();
'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.
I'm working with Yii2 to develop an intranet portal.
I have to put multiple widget in same page but it doesn't work.
Give me this error
Dropzone already attached.
And my code is
...
<?= \kato\DropZone::widget([
'id' => 'dzImages',
'dropzoneContainer' => 'dzImages',
'options' => [
'url' => 'index.php?r=orders/upload&uid='.$model->ref,
'maxFilesize' => '10',
'acceptedFiles' => "image/*",
],
]); ?>
</p>
<p>
<?php echo \kato\DropZone::widget([
'id' => 'dzPDF',
'dropzoneContainer' => 'dzPDF',
'options' => [
'url' => 'index.php?r=orders/uploadpdf&uid='.$model->ref,
'maxFilesize' => '10',
'acceptedFiles' => ".pdf",
],
]);
?>
</p>
...
How can i resolve it?
Looking at the code of the widget, the 'id' parameter seems to be used differently than one would expect, instead you should probably set previewsContainer property too.
The ID parameter seems to be used as a JavaScript variable here:
https://github.com/perminder-klair/yii2-dropzone/blob/41e8145d940cc9955011138a9f16ad80e9831423/DropZone.php#L75
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',