Define A List Of Choices

I would like to define a list of choices for a field in a php file or something similar.

The choices can be in simple text. (Example: a dropdown field with "private user" as text and "p" as value)

Can i do that?

Do i have to define a whole model?

You don’t have to define a model. What’s the specific use case?

I have 2 types of device to choose. But in the future there could be more.

If you have a model representing a device, I would put the type options in there.

dropdown list example

Thanks everybody, the Example n.3 from the link skworden posted perfectly suits my needs.

[i]Example 3: Using data from a model function.

It is better to have you gender list definition inside your model definition.

At model:


public function getGenderOptions(){

    return array('M' => 'Male', 'F' => 'Female');

}

At view:




<?php echo CHtml::dropDownList('listname', $select, 

              $model->genderOptions,

              array('empty' => '(Select a gender'));

[/i]