how to handle enum type

In my database there is some enum types which have static members.

e.g.

Gender => M - Male F - Female (in database char(1))

Status => A - Active, I - Inactive (in database char(1))

Enabled => 0 - Disabled, 1 - Enabled (in database bit)

Should I define the property (validation and view behaviour) in CModel class? or I need to define in every Views?

Regards.

P.S. It would be much better is more examples being put in the documentation.

I though it is more logical to define the mapping in the CModel class, isn't it?

You may want to take a look at Range validator

http://www.yiiframew…or#range-detail

Thanks, I know I can restrict the valid value of the field. However, I still have to assign key->value mapping manually in every form refer to the same field (foreign key)

e.g. in all view I need to define CHtml::activeListBox(…, array('A'=>array('label'=>'Active), 'I'=>array('label',=>'Inactive'));

If this can be defined in CActiveRecord it will be more convenience.

This is called lookup. You may or may not store them in a database table. In both cases, it makes sense that you define a static method in your model class which returns the associative array. And then, in the view, you may simply call this static method to get the list data.

There is a good example in the Blog tutorial - http://www.yiiframew…log/post.model