yii2

How to set multi select value from array object in yii2 while updating

可紊 提交于 2019-12-22 14:58:27
问题 I have table which have multiple reference to ohter tables like user id name email categories id title user_categories user_id category_id Here a user will have multiple category associated with him/her I am able to save these successfully with new records like following View File: echo $form->field($package_categories, 'category_id')->dropDownList( ArrayHelper::map( StudyMaterialCategories::find()->all(), 'id', 'title'), ['multiple' => true] ); Save New record: $model = new Packages();

yii2: Proper way to throw new exception

萝らか妹 提交于 2019-12-22 12:23:45
问题 Just for testing I have added this code in my model while setting the debug = true and false. if($packagedays < 1) { throw new \yii\base\Exception( "package days cannot be less than 1" ); } Now when Yii debug is true: I am getting Exception – yii\base\Exception package days cannot be less than 1 But when I am setting the debug to false I am getting Exception An internal server error occurred. The above error occurred while the Web server was processing your request. What I want is to replace

rate limit in yii2 vs using nginx for rate limiting

谁都会走 提交于 2019-12-22 11:38:07
问题 what is difference between rate limiting via yii2 versus using nginx for example as reverse proxy and rate limiter ? REF: Yii2 Rate Limiting Api 回答1: Application rate limit (like yii2) more flexible. You can write different limits per user, for example. Or put request to some queue for future execution. But each request over that limit still hit PHP scripts. Nginx limits less flexible, but allow to stop request before PHP script. Nginx limits usually used as DOS protection. Usual task: do not

rate limit in yii2 vs using nginx for rate limiting

一曲冷凌霜 提交于 2019-12-22 11:38:00
问题 what is difference between rate limiting via yii2 versus using nginx for example as reverse proxy and rate limiter ? REF: Yii2 Rate Limiting Api 回答1: Application rate limit (like yii2) more flexible. You can write different limits per user, for example. Or put request to some queue for future execution. But each request over that limit still hit PHP scripts. Nginx limits less flexible, but allow to stop request before PHP script. Nginx limits usually used as DOS protection. Usual task: do not

How can i show the default login page as modal popup in yii2?

狂风中的少年 提交于 2019-12-22 11:29:51
问题 Can anybody please tell me how can i raise the default login page as model popup in yii2? Thanks 回答1: Login link <a href="javascript:void(0);" onclick="login();return false;">Login</a> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div> <script> function login(){ $.ajax({ type:'POST', url:'index.php?r=site/login', success: function(data) { $('#myModal').html(data); $('#myModal').modal(); } }); } </script> In Controller

Debian - /usr/bin/env: 'php\r': No such file or directory

喜你入骨 提交于 2019-12-22 11:29:06
问题 So go straight to the problem, when I run ./yii seems I got that error from Debian:stretch that I ran from Docker. However when I run /usr/bin/env php -v I got the correct output and there's no problem on it. Seems there's a problem on new line being translated as string and I have no idea how to fix it. Sorry if my English a bit messy and thanks in advance. Just note: I've been trying to edit that file using nano within debian but it's useless. I'm getting the same error. I've check php file

Yii2 Email How to set sender name

泪湿孤枕 提交于 2019-12-22 09:47:49
问题 i using Mailer to send email, so i have problem about sender name This is my config 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => false, 'messageConfig' => [ 'charset' => 'UTF-8', 'from' => ['admin@app.com' => 'App Sender Name'], ], 'transport' => [ 'class' => 'Swift_MailTransport', ], ], So it's not work. I goto inbox and only email showed. And i need show as Example: 回答1: it's work when i update setFrom() method. Ex: $mailer->setFrom(['email@app.com' => 'App Name'

Yii2 - How to set dynamic authTimeout in User Identity?

半世苍凉 提交于 2019-12-22 09:46:26
问题 Here, I have extended User Identity of Yii2. This is my configuration. 'user' => [ 'identityClass' => app\models\UserMaster::class, 'enableAutoLogin' => false, 'loginUrl' => ['/auth/login'], 'authTimeout' => 86400 ], Here, I have defined authTimout statically. But, What I want to do is that I want to fetch timeout value from database and set it in authTimeout . Thanks. 回答1: You can use event to set authTimeout before request will be handled: 'as beforeRequest' => [ 'class' => function (Event

Yii2 AssetManager published path include URL scheme

核能气质少年 提交于 2019-12-22 09:40:21
问题 In my controller I have implemented a function for publishing a single asset, such as an image, and return the URL: /** * Publish an asset and return url * * @param $src * * @return mixed */ public function publishAsset( $src ) { $path = Yii::getAlias( $src ); if ( ! $this->assetManager ) { $this->assetManager = new AssetManager(); } $return = $this->assetManager->publish( $path ); return $return[1]; } And then call it in my view like this: <?= $this->context->publishAsset('@app/assets/img

Yii2 validation rule for multiple inputs with same name

旧城冷巷雨未停 提交于 2019-12-22 09:34:18
问题 I have one form which has multiple inputs with same name which are dynamically added using jQuery. Input names are as below: ModelName[dynamic_name][] ModelName[dynamic_name][] I have also declared dynamic_name as public variable in a Model . How can I validate the above inputs using yii2 validation rule? 回答1: Since your dynamic_name variable will be an array of input values, you can use the new each validator. It was added in v2.0.4. It takes an array and passes each element into another