CListData

Hi,

I am trying to get this working but it is not working.

Tried this …




$states = new States;

$view->models->states = $states;

$this->render("CreateOrEdit", array("view" => $view));



And this …




$states = new States;

$states = $states->findAll();

$view->models->states = $states;

$this->render("CreateOrEdit", array("view" => $view));






CHtml::listData(array($view->models->states), "id", "name");



The array is always empty so I know its not working.

Try this




CHtml::listData(States::model()->findAll(), "id", "name");



Pay attention…

Above… the value of $view->models->states is a new empty object States…

Above… the value of $view->models->states is the result of the findAll() - an array.

As $view->models->states in the second example is an array… here as the first parameter you are effectively sending "array( array() )"… so you just need to send $view->models->states without enclosing it in array()…

It works.

Thanks for your answer as well mdomba.