Model class for static data

Hi all,

I’m wondering what would be the “best” approach for this:

I need a list of countries for a dropdownlist. For this I’ve created a model class derived from CFormModel which holds a public $countries array containing all countries.

This model is passed to the form where it can be used to populate a dropdownlist by simply using $countryMode->counties.

Would this be the yii way to go?

How are the countries managed and stored… if they are in a database then it’s better to use CActiveRecord->findAll()…

if you read them from some txt file or code it manuali in the code than the array is OK

No need to use any CModel class (CFormModel) at all for this, as you’ll never validate these countries. A simple custom class with static methods will do also.


Ok, thanks for that.

Is there a guideline on how to create one’s own helpers or is it indeed just a custom class without any relation to yii’s classes?

No guideline. Just put it somewhere, Yii can find it. E.g. protected/components.

Yii is a very open framework. It doesn’t limit you in any way. So whatever works for you is fine. :)

Also check this:

Ok, thanks, I did create a static helper class, far simpler than my initial solution!