Implementing some Model's predefined attribute's value

Hi everyone,

I’m a Yii newbie workin on his first project, actually i’ve designed the whole db model but I’m wondering about how to define some model’s attribute that can assume a limited set of values. I’ve tried to look around in this forum with no results

For Instance, suppose to have the "Connection" of which I want to be able do describe its speed value, in the project speed can be defined with two attributes "capacity" and "capacityUnit". For capacityUnit the only value admitted are "Mbit/s" and "Kbit/s".

Which is the best way to describe this in the Model? As a new Class capacityUnit and a one-to-many relationship could be fine? Basically the final result must be that in my view i can pick the capacity unit from a combo box.

Thank you

These are all model validation problems. http://www.yiiframework.com/wiki/56/

Imho, best way is use RegexpValidator:




.. rules...

array('capacityUnit', 'match', 'pattern'=>'/^(Gbits|Mbits|Kbits)$/'),



I’d prefer




array('capacityUnit', 'in', 'range'=>array('Gbits', 'Mbits', 'Kbits')),



Ok that’s great, so I can easily avoid to keep trace of similar data in my DB and just set them up as rules. Maybe is not the best way for decoupling code and data model but for my needs it’s gonna fit pretty well :)

Thank you!