What I am trying to do is populate the category_id field in a drop down list in a create form that pulls all the categories from the tbl_category table. I looked up the code for this and added the following code in the public function actionCreate() located in the content controller:
public function actionCreate()
// retrieve the category model from db
$categorymodel = Category::model()->findAll(
array('order' => 'description'));
// format list as $key=>$value with listData
$categorylist = CHtml::listData($categorymodel,
In the view _form, I then reference the $categorylist as my key=>value pairs to populate the dropdown:
<?php echo CHtml::dropDownList('category_id', $select, $categorylist, array('empty' => '(Select a category'));?>
I am getting the following error when I try and access the form:
"Invalid argument supplied for foreach()"
Can someone tell me what I am doing wrong here. Are my naming conventions incorrect?
Hello there im having a problem creating a dynamic drop down list, i’ve tried this method and it does create a drop down list but when submitting its giving an error that categories cannot be blank can someone help what am i getting wrong?