I’m Trying to use DepDrop Widget of Kartik. However, the dependent dropdown does not display the array properly.
my _form
<?= $form->field($model, 'permanent_province') ->dropDownList(Province::getProvince(), ['id' => 'province_id']) ?> <?= $form->field($model, 'permanent_district')->widget(DepDrop::classname(), [ 'options' => ['id' => 'district_id'], 'pluginOptions' => [ 'depends' => ['province_id'], 'url' => Url::to(['district/sub']) ] ]); ?>
my Controller
public function actionSub()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$out = [];
if (isset($_POST[‘depdrop_parents’])) {
$parents = $_POST[‘depdrop_parents’];
if ($parents != null) {
$district_id = $parents[0];
$out = District::getDistrict($district_id);
return [‘output’ => $out, ‘selected’ => ‘’];
}
}
return [‘output’ => ‘’, ‘selected’ => ‘’];
}
my model
public function getDistrict($district_id)
{
return District::find()
->select([‘name’])
->where([‘id_province’ => $district_id])
->asArray()
->all();
}
output
Phpmyadmin, I’m Run SQL query/queries on the table is normal