Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:15:08+00:00 2026-06-05T11:15:08+00:00

I’ve been following this tutorial, which is great btw, and have one question. http://www.larryullman.com/2010/01/07/custom-authentication-using-the-yii-framework/

  • 0

I’ve been following this tutorial, which is great btw, and have one question.

http://www.larryullman.com/2010/01/07/custom-authentication-using-the-yii-framework/

I can access the role property like this, anywhere in my application code:

Yii::app()->user->role

but, what I’d really like to do is use the default controller authorization in my UserController:

/**
  * 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'=>array('*'),
    'users'=>array('@'),
    // Fails
    'roles'=>array(ModelConstantsRole::ADMIN),
    // Also Fails
    'expression'=>'(isset(Yii::app()->user->role) && (Yii::app()->user->role==ModelConstantsRole::ADMIN))',
   ),
   array('deny',  // deny all users
    'users'=>array('*'),
   ),
  );
}

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).

Any ideas on how I can make use of the accessRules method when I combine it with Larry’s approach?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:15:10+00:00Added an answer on June 5, 2026 at 11:15 am

    From your code it looks like you want to apply this rule to all the actions, to do that you need to leave the actions array unspecified or empty array:

    //empty actions
    array('allow',  
    'actions'=>array(),//array('*'),
    ...
    )
    

    Or unspecified:

    array('allow',  // allow all users to perform 'index' and 'view' actions
    //'actions'=>array('*'),
    ...
    )
    

    This is already documented in the docs :

    array(
    ‘allow’, // or ‘deny’
    // optional, list of action IDs (case insensitive) that this rule applies to
    // if not specified, rule applies to all actions
    ‘actions’=>array(‘edit’, ‘delete’),

    Keep in mind that the roles array is again an array with role names, example:

    'roles'=>array('role1','role2','role3')
    

    Then you don’t need the ‘expression’ as all that you are doing in there is already being done with the roles array.

    Edit: After reading the tutorial you have linked, it seems that he has not implemented RBAC. The 'roles' option uses rbac, so it won’t work without it. Hence you’ll have to use the 'expression' option instead, and your 'expression' option looks fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.