Ich benutze diesen Code auf backend/views/_form.php
Wie abhängig Drop-Down in yii2
<?php $CoursesCat = ArrayHelper::map(CoursesCat::find()->all(),'id', 'cat_name');
$CoursesSubcat = ArrayHelper::map(CoursesSubcat::find()->all(),'id', 'name');
$form = ActiveForm::begin(); ?>
<?php
echo $form->field($model, 'cat_id')->dropDownList($CoursesCat,
['prompt'=>'-Choose a Category-',
'onchange'=>'
$.post("'.urldecode(Yii::$app->urlManager->createUrl('coursedetail/lists&id=')).'"+$(this).val(), function(data) {
$("select#subcat_id").html(data);
});
']);
echo $form->field($model, 'subcat_id')
->dropDownList( $CoursesSubcat
['prompt'=>'-Choose a Sub Category-'],
['id'=>'subcat_id']
); ?>
bitte geben Sie 'CoursesSubcat' Tabellenstruktur – vishuB
diesen Link hilfreich für Sie http://www.yiiframework.com/wiki/723/creating-a-dependent-dropdown-from-scratch-in-yii2/ – jithin