Yii2 Tips 28 : Dependent Dropdown Without Extension
This tip will show you how to create dependent dropdown without using any extensions. 1. Create table country and table city. 2. Create models Country and City using gii. 3. Add actionDependentDropdown on your controller (i.e. TestController.php)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public function actionDependentDropdown(){ $model = new \common\models\City(); if($model->load(Yii::$app->request->post())){ echo "<pre>"; print_r($model); echo "</pre>"; die(); } return $this->render('dependent-dropdown',[ 'model'=>$model, ]); } |
4. Add the view file, dependent-dropdown.php inside the view folder, take note to the ‘onchange’ event when the Read more about Yii2 Tips 28 : Dependent Dropdown Without Extension[…]