Installing Yii-rights extension

Installing Yii-rights extension

Last updated:

These are the steps I've followed in order to install yii-rights extension for my project.

There are a little extra steps I've done which do not feature in the official docs so they might work for you too.

Stuff I've not included in this tutorial: database setting, gii usage. If you're not confident about these, you shouldn't be reading this tutorial at all. Go do the blog tutorial.

This tutorial assumes you're installing rights into a clean (newly created) Yii project.

Download the extension here (official Yii download link).

Extract the .zip file.

Copy the rights directory into your app's modules directory. (If your project has no modules directory, create it):

your_project
|
|----protected
    |----models
    |----modules
         |----rights

Now you need to add the following lines to you main.php configuration file (under protected/config).

Only the lines I've marked with //add this are supposed to be added. The other lines are included so that you know where it is.

'import' => array(
    'application.models.*',
    'application.components.*',
    'application.modules.rights.*',//add this
    'application.modules.rights.components.*',//add this
),

-

'modules' => array(
    // uncomment the following to enable the Gii tool
    'gii' => array(
        'class' => 'system.gii.GiiModule',
        'password' => 'Enter your password',
        // If removed, Gii defaults to localhost only. Edit carefully
        'ipFilters' => array('127.0.0.1', '::1'),
     ),
    'rights' => array(//add this
        'install' => true,//add this
    ),//add this
),

-

'user' => array(
        'class' => 'RWebUser', //add this
        // enable cookie-based authentication
        'allowAutoLogin' => true,
 ),

-

'authManager' => array(//add this
        'class' => 'RDbAuthManager',//add this
),//add this

Now navigate to rights index page: The route should be rights/index. You might be asked to login. demo/demo and admin/admin should suffice.

Now you might see a CDbException on your screen. Ok no problem. Just re-type the route on the address bar.

Now that CDbException should go away, but perhaps you'll get another message saying that Yii found no User class.

Ok so you create a table called user (with columns id and username at the very least), and generate the corresponding model using gii.

One you've created the User model, change the 'install'=>true line to 'install'=>false.

Ok good now point your browser to rights again. Now you might see yet another error message, saying: Error 403 There must be at least one superuser!.

Ok here comes a little ugliness. Brace yourselves!

I don't know why. I just know that it works - this phrase might have come before some of the hackiest hacks in the world.

Open up the file RAuthorizer.php under /modules/rights/components and comment out lines 304 and 305:

//if( $superusers===array() )
//  throw new CHttpException(403, Rights::t('core', 'There must be at least one superuser!'));

It looks very ugly but this hack is even listed at the official docs comment pages... If anyone know a better way to do this (any other way would be better than this)... drop me a line....