Hey,
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?
Page 1 of 1
Access Control And Dynamic Main Menu
#3
Posted 30 January 2013 - 02:03 AM
#4
Posted 30 January 2013 - 03:18 AM
To answer my own question for 1.
It looks like that the way to go is through the CActiveDataProvider in my controller
Any suggestions for question no 2?
It looks like that the way to go is through the CActiveDataProvider in my controller
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Item',
array(
'criteria'=>array(
'condition'=>'user_id=:userId',
'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
),
'pagination'=>array(
'pageSize'=>1,
),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
Any suggestions for question no 2?
Share this topic:
Page 1 of 1

Help














