Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing role-based authorization in Yii Framework
    text
    copied!<p>I've been following this tutorial, which is great btw, and have one question.</p> <p><a href="http://www.larryullman.com/2010/01/07/custom-authentication-using-the-yii-framework/" rel="nofollow">http://www.larryullman.com/2010/01/07/custom-authentication-using-the-yii-framework/</a></p> <p>I can access the role property like this, anywhere in my application code:</p> <pre><code>Yii::app()-&gt;user-&gt;role </code></pre> <p>but, what I'd really like to do is use the default controller authorization in my UserController:</p> <pre><code>/** * Specifies the access control rules. * This method is used by the 'accessControl' filter. * @return array access control rules */ public function accessRules() { return array( array('allow', // allow all users to perform 'index' and 'view' actions 'actions'=&gt;array('*'), 'users'=&gt;array('@'), // Fails 'roles'=&gt;array(ModelConstantsRole::ADMIN), // Also Fails 'expression'=&gt;'(isset(Yii::app()-&gt;user-&gt;role) &amp;&amp; (Yii::app()-&gt;user-&gt;role==ModelConstantsRole::ADMIN))', ), array('deny', // deny all users 'users'=&gt;array('*'), ), ); } </code></pre> <p>It appears that the class that actually validates the rules defined in accessRules doesn't actually know anything about my role that I've assigned it. CAccessControlFilter (for those of you who don't want to search for it for 40 minutes XD).</p> <p>Any ideas on how I can make use of the accessRules method when I combine it with Larry's approach?</p> <p>Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload