Reputation: 347
I have a table in my database, one of it fields data type is ENUM
now i am working in Yii framework, and I want to make a dropdown box and the list that we want to use is the lists that contain in ENUM
.
Example:
table x
field -> category -> ENUM(HARD,MEDIUM,EASY)
I want to make a dropdown box and the option is HARD
, MEDIUM
, and EASY
Upvotes: 3
Views: 3268
Reputation: 1364
You can also use params for the same in Yii.
Ex: Define categoryValues under "params" array in config file.
'params' => array(
'categoryValues'=>array(
'EASY',
'MEDIUM',
'HARD'
),
),
Use :
echo $form->dropdownList($model , 'category' , Yii::app()->params['categoryValues']);
Upvotes: 0
Reputation: 7265
make a function in your model to return an array of your list:
public function getOptions()
{
return array(
'EASY',
'MEDIUM',
'HARD',
);
}
then you could use it like this:
echo $form->dropdownList($model , 'category' , $model->options); // this will use that function to get the array
Upvotes: 5