Access Control And Dynamic Main Menu


I’m pretty new to Yii but have a good understanding of the MVC pattern, mainly due to my experience with joomla.

Anyway, some noob questions:

  1. I have implemented a basic role access control and managed to restrict access to menu items using accessRules. However, when displaying a list of items in my index view (lets say products) I want the logged in user to only have access to those items that he has uploaded (there is a foreign key connection between product and user). How should I go for this? Is this something we implement with filters? Right now all users are allowed to index all items but not edit them since I managed to restrict editing via the accessRules.

  2. I was wondering if there is a way to have a main menu with items retrieved from database defined only once on my main layout. I do understand that layouts inherit from views and that is possible to define the main menu on each controller/view, but is there a way to generate only once the menu for a logged in user and then make my layout to use that one?

Check this.

Thank you for your answer but apparently this was not my question, Ive already done taht ;)

To answer my own question for 1.

It looks like that the way to go is through the CActiveDataProvider in my controller

  public function actionIndex()


    $dataProvider=new CActiveDataProvider('Item',




                'params'=>array(':userId'=>Yii::app()->user->id), //Here we add a condition for the data provider to only display items owned by the logged in user










Any suggestions for question no 2? :)