I am very new to PHP frameworks in general and MVC framework in particular. After several hours of googling, I came to a conclusion that Yii is the best (for me, at least). I am writing this post so that it can serve as a reference for me as well as others.
I closely followed the blog tutorial and use it as a basis for my application. My application has a Contact Management system, which is very similar to the Blog. Just like the Blog has the Post and the Comment, it has Company and Contact. Let us move on with the Tutorial.
In order to have a One Company to Many Contacts view for the Company, make following changes, after the model *, crud Company and crud Comment execution.
- In the model/Company.php file
add the following code to the relationship function.
public function relations()
'contacts' => array(self::HAS_MANY, 'Contact', 'contact_company_id', 'order'=>'contact_id ASC'),
'contactCount' => array(self::STAT, 'Contact', 'contact_company_id'),