yii2

Add custom field in the view of yii2 which is not in model

帅比萌擦擦* 提交于 2019-12-10 21:45:17
问题 I am getting a problem while saving a form in yii2. I have created a custom field with name like other fields Myposts['categoryLevel2'] . This field is not in model. It is a conditional field. When I post my from I assign its value to a model attribute Like: $categoryLevel3 = $request->post('categoryLevel3'); if(!empty($categoryLevel3)){ $model->category=$categoryLevel3; } Now because categoryLevel3 is not there in table post so it is giving error. Getting unknown property: frontend\models

How to display selected values in multiple select dropdown in a Yii2 app?

放肆的年华 提交于 2019-12-10 21:05:38
问题 I am working on Yii2. I am creating multiple select drop down using custom array like this. In controller file: $all_groups = Groups::find()->where(['=','group_created_by',$id])->orwhere(new Expression('FIND_IN_SET(:id_to_find, group_managers)'))->addParams([':id_to_find' => $id])->all(); // fetch all values $selected_groups = Groups::find()->where(['=','group_users',$updateId])->orwhere(new Expression('FIND_IN_SET(:id_to_find, group_users)'))->addParams([':id_to_find' => $updateId])->all();

Yii2 form submit button must be clicked two times for action. How to prevent this?

巧了我就是萌 提交于 2019-12-10 20:48:33
问题 yii2 submit button needs to be clicked two times in form I have a problem where I need to check more than one submit buttons in the controller. It works but I need to click submit buttons two times. In controller : switch(\Yii::$app->request->post('submit')) { case 'submit_1' : //my code break; case 'submit_2' : //my code In view <?= Html::submitButton('NEXT', ['name' => 'submit', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?> <?= Html::submitButton('PREVIOUS', ['name' =>

Yii2: scenarios() model method

半城伤御伤魂 提交于 2019-12-10 20:15:32
问题 There are 2 needed functions: set password when registering and change password, if user forgot it. When user signs up, password length must be at least 4 chars; when changes pass - at least 5 chars. View is common for registration and changing pass. Obviously, also 2 actions exist, in which either scenario 'signup', either 'change' used. Code snippet in model: public function rules() { return [ ['password', 'string', 'min' => 4, 'on' => 'signup'], ['password', 'string', 'min' => 5, 'on' =>

Container-fluid in navbar yii2

心已入冬 提交于 2019-12-10 19:05:14
问题 I am starting learning yii2, I want to create layout like this : http://www.yiiframework.com/doc-2.0/ext-bootstrap-index.html I am little confused, how yii write the bootstrap nav. I want to create nav to container-fluid. I have a write in html on codeigniter like this : <nav class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded=

Should i calling model direct from view yii2

偶尔善良 提交于 2019-12-10 18:49:19
问题 I'm little confused cuz, here in view they do direct call to model thus not passing it through the controller. http://www.yiiframework.com/doc-2.0/guide-input-forms.html Scroll to the bottom of the page... echo $form->field($model, 'product_category')->dropdownList( ProductCategory::find()->select(['category_name', 'id'])->indexBy('id')->column(), ['prompt'=>'Select Category'] ); And the guide from here http://www.yiiframework.com/doc-2.0/guide-structure-views.html at the bottom again there

How can we use the auth_rule table in Yii2 RBAC?

南楼画角 提交于 2019-12-10 18:42:38
问题 In Yii 2 RBAC, there is a new table called auth_rule . Can anyone explain its usage with a small example create table [auth_rule] ( [name] varchar(64) not null, [data] text, [created_at] integer, [updated_at] integer, primary key ([name]) ); 回答1: The basic parts of yiis RBAC-cconcept stayed exactly the same. In both Yii1 and Yii2 you have the following tables: auth_item : holds the actual rights, groups, roles, etc. auth_item_child : defines the graph / hierarchy of the items auth_assignement

Yii2, Kartik DepDrop on update pre selected value

喜欢而已 提交于 2019-12-10 18:28:09
问题 I have four dependent drop downs of hierarchy library > catalog > category > subject I am using kartik depdrop , every thing is working really fine but on update I couldn't find any solution for pre selected values. What I need is to show pre selected values on update with all other values as well so that user can change the selection also. Here is my code. _form.php <div class="inner-addon right-addon"> <div class="catalog-input"> <span><strong>Library</strong></span> <?php echo $form->field

Server Side file validation Don't work in Yii.2.0

岁酱吖の 提交于 2019-12-10 18:27:26
问题 Is the FileValidator class in Yii2 only supports clientside validation ? I written the file upload system with the use of code : in model: public function rules() { return [ [['allAllowedFileType'], 'safe'], [['allAllowedFileType'], 'file', 'extensions'=>'jpg', 'mimeTypes' => 'image/jpeg'], ]; } in controller: public function actionCreate() { $model = new File(); if ($model->load(Yii::$app->request->post())) { // get the uploaded file instance. for multiple file uploads // the following data

Yii2 migration problems

◇◆丶佛笑我妖孽 提交于 2019-12-10 18:25:12
问题 I am using yii2 for the first time, and I wanna trying yii migrations. The problem: I created migration file with php yii migrate/create new_table file is created. then I input new table details into migration file. and when I run php yii migrate I got error Exception 'ReflectionException' with message 'Class db does not exist' in /var/www/yii2.uz/vendor/yiisoft/yii2/di/Container.php:415 what's the problem? my console/config/main.php : <?php $params = array_merge( require(__DIR__ . '/../..