_form.php
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use app\models\Category;
?>
<?php $form = ActiveForm::begin(); ?>
$model = Category::find()->select('id,name')->orderBy('name asc')->all();
$listData = ArrayHelper::map($model, 'id', 'name');
<?= $form->field($model, 'industryId')->dropDownList($listData,
['prompt'=>'Select Category',
'onchange'=>'
$.get("'.Url::toRoute('/category/subcats').'", { id: $(this).val() })
.done(function(data) {
$("#'.Html::getInputId($model, 'sub_category').'").html(data);
}
);
','class' => 'form-control'
]
); ?>
<?= $form->field($model, 'sub_category')
->dropDownList(
['prompt'=>'Select sub cat','class' => 'form-control']);
?>
----
kodun ilgili kısmını göstermek ve denenmiş ve ne oldu ne yanlış olduğunu ne açıklayınız. – betseyb
[this] (http://www.yiiframework.com/wiki/723/creating-a-dependent-dropdown-from-scratch-in-yii2/) size yardımcı olacaktır. –