if412010
if412010

Reputation: 347

Dropdown Box With ENUM in Yii

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

Answers (2)

Bhavin Solanki
Bhavin Solanki

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

Developerium
Developerium

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

Related Questions