How To Create A User Area, Separate To The Admin Area

Hi,

This is my first post, and I’m still learning my way around. So bare with me :)

I’ve started to build two projects using Yii, both of which share common characteristics. One of these is the ability for users to log in and look at the information on the site.

At the moment, I have followed the tutorial, so I have a basic Yii project set up. I have created the views and the CRUD’s for the project. However, I have no idea how to create separate user areas. What I mean by this, is that I want to create an Admin area for complete administration of the website. Then, aside from this, I want to create a Client User area, where clients can log in and view specific information.

However, I am completely fresh to Yii and I don’t seem to be able to figure this out. I understand this could be incredibly simple (like most things in Yii have been so far), but I just can’t figure it out.

Any help would be appreciated!

Cheers,

Michael

Hi Michael,

Take a look at RBAC (Role Based Access Control) as a possible solution:

http://www.yiiframework.com/doc/guide/1.8/en/topics.auth

I haven’t actually used it myself yet, but will do in the very near future.

Hope this helps.

Scott.

Thank you very much! I will look in to this and if you like I’ll let you know how it helped me if you want?

Cheers,

Michael

+1 What did you find?

Also consider making a separate admin ‘module’.

I’ve previously played with an admin module, however found there was too much code repetition.

I have also played with various RBAC extensions, however found them more complex than I require.

I now have a ‘user_role’ column in my user table and access this in the authenticate() method of UserIdentity when the user logs in, eg.:




    $record=User::model()->findByAttributes(array('username'=>$this->username));

    if($record===null)

        $this->errorCode=self::ERROR_USERNAME_INVALID;

    else if($record->password!==md5($this->password))

        $this->errorCode=self::ERROR_PASSWORD_INVALID;

    else

    {

       if($record->user_role == 'admin') {

         $this->setState('user_role', 'admin');

       } // etc.

    }


    // can be accessed using:

    $role = Yii::app()->user->user_role;



I then use theme and access control based on user_role.