I got 3 tables: Users, Flags and Answers. Answers gots FlagID and UserID (many to many). On top of these models I made a CForm GameForm which defines HTML Form data. Then a GameController takes this user input (FlagID, FlagValue and, somewhere in the back, UserID) and compares with FlagValue in Flag table. If match, a record is added in the table Answers (flagID, UserID, time).
My questions: is it good practice
if the GameController does all the compare and logic by communicating with the three Models only? Or should it interact with their Controllers?
to call a method in Flag model (to interact with DB), I have to create a Flag Model instance in my GameController ?
this is my first PHP application. I’ve been reading a lot these days on Yii (so many good things!), so hadn’t courage to screen all topics, sorry…
Depends on the method. If you are just finding out if the ‘flag_id’ exists then
No need for an instance. I would lean toward the only reason to create an instance is is you are CRUDing. Just getting info, i’d go with Flag::model()->.
I quite often set up a public function getDataList() in my models for use with dropDownLists. I would call it from what ever controller by:
Something I’ve been doing on my sites is generating controllers for each of the main items in the mainmenu, then actions within for each of the ‘sub-items’. In one site, there is a User Profile that can be modified by only the logged in user. I have User and Profile models, but they are accessed through the SiteController actionViewProfile(), actionUpdateProfile().