In yii2 how to change Dropdown data based on role?

I have the data in the drop-down list according to the role (for each table of roles different). I do not know how to do this because I am not familiar with yii2. First, select a role, and after choosing a role, I want data from different tables depending on the role

<?= $form->field($model, 'role')->dropDownList( [ 'A' => 'Admin', 'M' => 'Member', 'P' => 'Practice', ],['prompt'=>'--Select a Role--',]);?>
<?= $form->field($model, 'code')->dropDownList(
                    ArrayHelper::map(Member::find()->all(), 'id', 'memberCode'),           
                            ['id'=>'memberCode']
                        );
                    ?>
+4
source share
2 answers

Refer to Kartik Dependent Drop Down in Yii2 . This will definitely help.

+1
source

, 1-. , 2- id # dropdown2, , dit yii yii2.

 echo $form->dropDownListGroup(
                    $model, 'id', array(
                'wrapperHtmlOptions' => array(),
                'widgetOptions' => array(
                    'data' => CSystemGenerated::getProjectName($model->c_id),
                    'htmlOptions' => array(
                        'prompt' => 'Select Project',
                        'ajax' => array(
                                'type' => 'POST',
                                'url' =>  your url,
                                'update' => '#dropdown2',
                                //'dataType' => 'json',
                                'data'=>array('id'=>'js:this.value'),

                              )
                            ),
                        ),
              )
            );   

 <?php
            echo $form->dropDownListGroup(
                    $model, 'tag', array(
                'wrapperHtmlOptions' => array(),
                'widgetOptions' => array(
                    'data' =>$this->getTags(),
                    'htmlOptions' => array(
                        'prompt' => 'Select Tags',
                    ),
                )
                    )
            );
        ?> 

, .

Link1

link2

+2

Source: https://habr.com/ru/post/1621110/


All Articles