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.
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.
The blog tutorial uses $_groups[item] which does return false for isset, but I am using a single array which returns true for isset. I had no idea about that.
I could use this instead:
if(empty(self::$_groups))
self::loadGroups();
or
if(!isset(self::$_groups[0]))
self::loadGroups();
I thought the mistake was on loadGroups although I could see that it was never called because the trace never pulled through. It was a silly php question then
This is probably more of a coding preference question that I have. I know that for my purpose I want to use the class that I built but why would someone prefer the second method over the first.