Trying to use DepDrop Widget of Kartik. However, the dependent dropdown does not display the array properly.
Here’s a function in the controller…
public function actionSubcat() {
$out = [];
if (isset($_POST[‘depdrop_parents’])) {
$parents = $_POST[‘depdrop_parents’];
if ($parents != null) {
$cat_id = $parents[0];
$out = Listofvenues::getSubCatList($cat_id);
echo Json::encode([‘output’=>$out, ‘selected’=>”]);
return;
}
}
echo Json::encode([‘output’=>”, ‘selected’=>”]);
}
Here’s getSubCatList which I modified
public static function getSubCatList($cat_id){
$subCategories = self::find()
->select([‘examVenue’])
->where([‘location_locationID’=> $cat_id])
->all();
return $subCategories;
}
Now it displays
Solved the problem. it was on the table itself. previously, i used different column names on tables like examVenueID and examVenue. then i used them in the select when using find(). Solution: I created another table and changed columns to id and name. Now it works.I guess id and name should be the column names.
0 Comments