简体   繁体   English

在yii2中如何根据角色更改下拉数据?

[英]In yii2 how to change Dropdown data as per role from?

I have data in Drop down list as per role(for every role table are different). 我根据角色在下拉列表中有数据(每个角色表都不同)。 I don't have any idea how to do because I am not familiar with yii2 First select a role and after selecting role I want data from different different table as per role 我不知道该怎么做因为我不熟悉yii2首先选择一个角色并在选择角色之后我想要根据角色从不同的不同表中获取数据

<?= $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']
                        );
                    ?>

You Need to update your 2nd dropdown when you select any value from dropdown 1st. 当您从下拉列表中选择任何值时,您需要更新第二个下拉列表。 Lets say 2nd drop down have id #dropdown2 so, i dit in yii you can change it according to yii2. 让我们说第二次下拉有id#dropdown2所以,我在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',
                    ),
                )
                    )
            );
        ?> 

check this link it will help you more. 检查此链接它会对您有所帮助。

Link1 链接1

link2 LINK2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM