I am new to Yii and MVC but I am trying to figure something out. I have a problem with a dropDownList and using an CActiveRecord model. I have been following the Blog tutorial.
The sql table is like this:
| id | name |
| 1 | Admin |
| 2 | Moderator |
The model is in the base of the application while the view _form.php is under a module called admin.
By using the model attached, and the code below:
<?php echo $form->dropDownList($model, 'idUserGroup', UserGroup::getGroups()); ?>
My dropDownList is empty.
When I use the following (Larry Ullman’s tutorials):
<?php echo $form->dropDownList($model, 'idUserGroup', CHtml::listData(UserGroup::model()->findAll(), 'id', 'name')); ?>
The code works,and I get my dropDownList.
I tried on the attached class to just return the $model from the :loadGroups() method using the second piece of code but no luck either. var_dump(UserGroup::getGroups()) on _form.php returns NULL
You might wonder since it works why do you bother. I just need to understand. I like using things and code but I like to understand what it is that I use. This for me makes no sense. I know that this type of code will come in quiet handy. So please explain.
Thanks for your help.