CHtml::dropDownList - Select Query From Database | YII
Generate DropdownList from database .
In order to create a dropdownList with data from db, you have to combine it with listData method that will format models from db into array of $key=>$value.
This part is equal to listData Example :
Now, we generate our dropdowList from the $list variable
In order to create a dropdownList with data from db, you have to combine it with listData method that will format models from db into array of $key=>$value.
This part is equal to listData Example :
// retrieve the models from db $models = categories::model()->findAll( array('order' => 'category_name')); // format models as $key=>$value with listData $list = CHtml::listData($models, 'category_id', 'category_name');
echo CHtml::dropDownList('categories', $category, $list, array('empty' => '(Select a category'));
Post a Comment