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 7489799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:22:33+00:00 2026-05-29T15:22:33+00:00

I am very very new to Yii. I am developing a real world example.

  • 0

I am very very new to Yii. I am developing a real world example.
I have a table,hence a model, called user which gets the data from database. Three main fields in Database are username,password and userRole.
Username and password work just fine.
All I need to look at the userRole in database and based on that, assign a role to a user.
For example is the user’s userRole field ==1, the user is admin and can Create, Read,Update and Delete (CRUD).
But if user’s userRole ==2, user can Update and Create but not delete.
I tried to do it with ‘expression’ ib accessRules() in UserController.php but it didnt work.
Then I read about it and found I should do it with role.
That’s what I wrote:

public function accessRules()
    {
        $auth = Yii::app()->authManager;

        $auth->createOperation('createUser','create a user');
        $auth->createOperation('updateUser','update a user');
        $auth->createOperation('deleteUser','delete a user');

        $role=$auth->createRole('creator');
        $role->addChild('createUser');

        $role=$auth->createRole('updater');
        $role->addChild('updateUser');

        $role=$auth->createRole('deleter');
        $role->addChild('deleteUser');


        return array(
................................
        array('allow',
            'actions'=>array('create','update'),
            'users'=>array('@'),
            'roles'=>????,

.....................

??? is where I have no idea what to do.
Am I defining the createOperation/addChild in a right place/file?
How can I use ‘roles’ in the returning array?
Also where should I get the userRole from Database?

I am desperately looking for answer as Yii Forum is not active

Thank you

  • 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-05-29T15:22:33+00:00Added an answer on May 29, 2026 at 3:22 pm

    you must assign role(s) to logged user (or by known user id)

    $auth->assign('creator',user()->id);
    $auth->assign('updater', 102); //102 as user id
    //...
    

    And in accessRules you must write

    'actions'=>array('create','update'),
    'roles'=>array('creator','updater'),
    

    Is this answeryou are looking for?

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

Sidebar

Related Questions

Very new to Iphone development here, I have a project which is successfully building
I very new to Python, and fairly new to regex. (I have no Perl
Im very new to all coding including jquery. I though this would have been
I am very new to jQuery and javascript. I have an autocomplete box setup
Very new to this, and I have no idea where to start. I want
Very new to Business Objects, but I have a .NET background and PL/SQL background.
Very new to JS here. When I write PHP I have no problem assigning
Im very new to this android development.I just started to create a hello world
Am very new to Oracle triggers. Suppose I have a trigger on an insert
am very new to this community 192.168.10.159:35621 communicates with 192.168.10.40:9000 where i have act

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.