Yii Framework Forum: Access Control And Dynamic Main Menu - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Access Control And Dynamic Main Menu Rate Topic: -----

#1 User is offline   yiipas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-January 13

Posted 29 January 2013 - 10:56 AM

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?
0

#2 User is offline   Aneesh Asokan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 237
  • Joined: 26-September 12

Posted 29 January 2013 - 01:06 PM

Check this.
http://www.yiiframew...28/simple-rbac/
Thanks
Aneesh.
0

#3 User is offline   yiipas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-January 13

Posted 30 January 2013 - 02:03 AM

View PostRvr101, on 29 January 2013 - 01:06 PM, said:



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

#4 User is offline   yiipas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-January 13

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
  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? :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users