Yii Framework Forum: [Solved]Different View (On Actionindex) Depending On User's Role - Yii Framework Forum

Jump to content

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

[Solved]Different View (On Actionindex) Depending On User's Role Rate Topic: -----

#1 User is offline   Remy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 11-December 13

Posted 11 December 2013 - 06:11 AM

I'm a beginner in Yii Framework, and I have a problem I can't fix. I have this in my class controller :

public function actionIndex()
{
  $dataProvider=new CActiveDataProvider('Absence');
  $this->render('index',array(
    'dataProvider'=>$dataProvider,
  ));
}


That gives me a list of all 'absence'.

Attached File  absence.bmp (774.23K)
Number of downloads: 1

In my case, 'erty' is logged in and sees a list of every absence. But, with his role, stored in my user's table, I want him to see only a list of absences with his 'Collaborateur alias'. Can someone helps me with it ?
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,707
  • Joined: 04-March 10
  • Location:UK

Posted 11 December 2013 - 08:11 AM

Moved from Bug Discussions to General Discussion for Yii 1.1.x.
0

#3 User is offline   Remy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 11-December 13

Posted 13 December 2013 - 03:33 AM

I solved my problem, now actionIndex is like that:

public function actionIndex()
        {
                if ( (Yii::app()->user->getState('roles') === 'user') )
                {
                        $criteria=new CDbCriteria;
                        $criteria->compare('collaborateur_alias', Yii::app()->user->id );
                        $dataProvider=new CActiveDataProvider('Absence', array( 'criteria'=>$criteria));
                        $this->render('index',array(
                                'criteria'=>$criteria,
                                'dataProvider'=>$dataProvider,
                        ));
                }
                else
                {
                        $dataProvider=new CActiveDataProvider('Absence');
                        $this->render('index',array(
                                'dataProvider'=>$dataProvider,
                        ));
                }
        }


If the logged in user have a 'user' for role, he only sees a list of his absences.
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