yii2

Yii2 Exception in ValidatePassword()

允我心安 提交于 2019-12-13 00:47:09
问题 I use yii2 for developing web site. Before save user to db, I encripted password like this: $this->password = Yii::$app->security->generatePasswordHash($this->password); And when I use this code: Yii::$app->security->validatePassword("some string", $this->password); I have error: Invalid Parameter – yii\base\InvalidParamException Hash is invalid. What is wrong? 回答1: I ran into the same issue. I realized that my password field's character capacity was too short for the hash, so I bumped it up

Yii2: How to send new variable from view to controller?

安稳与你 提交于 2019-12-12 21:35:10
问题 I have a table called persons with id and name fields. I have a create.php view that loads the model called Persons and now I want to add a checkbox called hasCar to show if a person has a car (so it is a boolean condition). Then I have the send button that send the $model array of the form to the controller so I need to add the hasCar variable to $model array. But the checkbox is not a column of the persons table so I got some errors because it is not part of the model. I added the checkbox

Register an asset in Yii2 for all views in a module?

寵の児 提交于 2019-12-12 19:19:44
问题 I have a module in Yii2 containing a lot of controllers, models and views. How can I register an asset for all views, without register it in all view one by one? 回答1: The module has init() method, you can use it for code that needs to be executed every time the module is accessed: <?php namespace frontend\modules\users; use frontend\assets\UsersAsset; use Yii; use yii\base\Module as BaseModule; class Module extends BaseModule { /** * @inheritdoc */ public $controllerNamespace = 'frontend

Yii2 redirect causes blank page

半腔热情 提交于 2019-12-12 19:12:10
问题 Is there any server/hosting setting that could cause simple redirect in Yii2 to not work? For example: function actionIndex(){ return $this->redirect('other-page'); } This code ends up with a blank page, no errors or messages are displayed(Error reporting is on), response code is 200 (although Yii2 debugger shows 302). Everything on my website works fine but as soon as code reaches any ->redirect() it just end up with blank page. This happens only on my clients shared hosting (on my local

400 Bad Request after sending AJAX post request in Yii 2

时光怂恿深爱的人放手 提交于 2019-12-12 18:29:15
问题 I want to post data via ajax to some specific controller like this : <script> var myUrl = "<?php echo Url::to(['table/edit']); ?>"; </script> $.ajax({ type : "POST", url : myUrl, data: {id: userID}, success : function(response) { alert("Table is editted"); } }); And in the controller I want to get this posted data and do some thing else. But when I try this I am getting an error "400 (Bad Request)". If someone can help it would be great! Thanks! 回答1: Just add csrf like : <script> var myUrl =

Yii2 - ListView search form

岁酱吖の 提交于 2019-12-12 18:14:27
问题 The problem: All the code below was made to filter in a ListView widget using a dropDownList form. The form fetch categorias table in DB model and it was supposed to filter products from the ListView $dataProvider by what is in categorias table. Results: It does not work. Nothing happens when i press the categorias button in the form. It just flickers and show all Products again as it was before. The screen with the form and ListView showing products inside a detailView: Produtos Controller

Yii2 unique validator ignored

只谈情不闲聊 提交于 2019-12-12 17:35:34
问题 In the rules() of my RegisterForm model: [ 'user_username', 'unique', 'targetClass' => 'app\models\User', 'message' => 'This username is already been taken.' ], In my controller: $model = new RegisterForm(); if ( $model->load( Yii::$app->request->post() ) ) { if ( $user = $model->register() ) { return $this->redirect( [ '/login' ] ); } } In RegisterForm: public function register() { $user = new User(); $user->user_firstname = $this->user_firstname; $user->user_lastname = $this->user_lastname;

How to use findAll() in yii2?

孤街醉人 提交于 2019-12-12 17:16:54
问题 I want to know how can i get all data of user with array id for where condition In yii you could do something like this $students = Student::model()->findAll("id IN ({$_POST['studentIds']})"); or $userDtls = Student::model ()->findAllByAttributes ( array ( 'id' => explode ( ",", $_POST ['studentIds'] ) ) ); Now in yii2 CDbCriteria is not there, so which approach should i use to achieve same thing?? I have tried this but it only returns data for first id in the array $result = Users::findAll([

How to render youtube video in YII2 DetailView widget

百般思念 提交于 2019-12-12 17:16:06
问题 I'm displaying you-tube video on front end of the website. Admin can provide the you-tube source from embedded code from Site back end. I want to have a preview on view page. Following is the code I tried but it is displaying the iframe tags as it is (I know this is not the right way) [ 'attribute'=>'source', 'value' => !empty($model->source) ? '<iframe class="embed-responsive-item" src="'.$model->source.'" frameborder="0" allowfullscreen></iframe>' : NULL, ], is there any thing like it has

How to combine 2 arrays that have the same index and value with php?

廉价感情. 提交于 2019-12-12 17:03:22
问题 I have 2 array like follows: $array1 = [ '0' => [ 'no_invoice' => 'INV0001', 'product_code' => '1111111', ], '1' => [ 'no_invoice' => 'INV0001', 'product_code' => '1111112', ] ]; $array2 = [ '0' => [ 'product_code' => '1111112', 'free_valie' => 839, 'count' => 1240 ], ]; Is it possible to combine arrays above to be like this: Array( [0] => Array ( 'no_invoice' => 'INV0001', 'product_code' => '1111111', ) [1] => Array ( 'no_invoice' => 'INV0001', 'product_code' => '1111112', 'free_valie' =>