Note that there are some explanatory texts on larger screens.

plurals
  1. POYii not giving Valid checkAccess results
    primarykey
    data
    text
    <p>I am learning Yii and am trying to develop RBAC now the issue is that I have created roles and so on executed that script via shell I have database tables in place and that Roles and everything gets populated. now I donot know why but </p> <pre><code>if(Yii::app()-&gt;user-&gt;checkAccess('admin')) echo 'Admin'; else echo 'No Admin'; </code></pre> <p>always return No admin .What I am trying to do is display a different menu based on user type i.e it is admin or reader or manager and so on. but this fails.</p> <p>I am attaching my role assignment also here</p> <pre><code>&lt;?php class RbacCommand extends CConsoleCommand { private $_authManager; public function getHelp() {return &lt;&lt;&lt;EOD USAGE rbac DESCRIPTION This command generates an initial RBAC authorization hierarchy. EOD; } /** * Execute the action. * @param array command line parameters specific for this command */ public function run($args) { echo "SHELLLLLLLLLL.\n"; //ensure that an authManager is defined as this is mandatory for creating an auth heirarchy if(($this-&gt;_authManager=Yii::app()-&gt;authManager)===null) { echo "Error: an authorization manager, named 'authManager' must be configured to use this command.\n"; echo "If you already added 'authManager' component in application configuration,\n"; echo "please quit and re-enter the yiic shell.\n"; return; } //provide the oportunity for the use to abort the request echo "This command will create three roles: Admin, Manager, and Reader and the following premissions:\n"; echo "create, read, update and delete Hotels\n"; echo "create, read, update and delete Items\n"; echo "create, read, update and delete Users\n"; echo "create, read, update and delete Category\n"; echo "Would you like to continue? [Yes|No] "; //check the input from the user and continue if they indicated yes to the above question if(!strncasecmp(trim(fgets(STDIN)),'y',1)) { //first we need to remove all operations, roles, child relationship and assignments $this-&gt;_authManager-&gt;clearAll(); //create the lowest level operations for users $this-&gt;_authManager-&gt;createOperation("createUser","create a new user"); $this-&gt;_authManager-&gt;createOperation("readUser","read user profile information"); $this-&gt;_authManager-&gt;createOperation("updateUser","update a users information"); $this-&gt;_authManager-&gt;createOperation("deleteUser","remove a user from a Hotel"); ////create the lowest level operations for projects $this-&gt;_authManager-&gt;createOperation("createHotel","create a new Hotel"); $this-&gt;_authManager-&gt;createOperation("readHotel","read Hotel information"); $this-&gt;_authManager-&gt;createOperation("updateHotel","update Hotel information"); $this-&gt;_authManager-&gt;createOperation("deleteHotel","delete a Hotel"); ////create the lowest level operations for Category $this-&gt;_authManager-&gt;createOperation("createCategory","create a new Item"); $this-&gt;_authManager-&gt;createOperation("readCategory","read Item information"); $this-&gt;_authManager-&gt;createOperation("updateCategory","update Item information"); $this-&gt;_authManager-&gt;createOperation("deleteCategory","delete an Item from a Hotel"); ////create the lowest level operations for issues $this-&gt;_authManager-&gt;createOperation("createItem","create a new Item"); $this-&gt;_authManager-&gt;createOperation("readItem","read Item information"); $this-&gt;_authManager-&gt;createOperation("updateItem","update Item information"); $this-&gt;_authManager-&gt;createOperation("deleteItem","delete an Item from a Category"); ////create the reader role and add the appropriate permissions as children to this role $role=$this-&gt;_authManager-&gt;createRole("reader"); $role-&gt;addChild("readUser"); $role-&gt;addChild("readHotel"); $role-&gt;addChild("readCategory"); $role-&gt;addChild("readItem"); $role-&gt;addChild("createUser"); ////create the member role, and add the appropriate permissions, as well as the reader role itself, as children $role=$this-&gt;_authManager-&gt;createRole("manager"); $role-&gt;addChild("readUser"); $role-&gt;addChild("readHotel"); $role-&gt;addChild("readCategory"); $role-&gt;addChild("readItem"); $role-&gt;addChild("createHotel"); $role-&gt;addChild("createCategory"); $role-&gt;addChild("createItem"); $role-&gt;addChild("updateHotel"); $role-&gt;addChild("updateCategory"); $role-&gt;addChild("updateItem"); $role-&gt;addChild("deleteHotel"); $role-&gt;addChild("deleteCategory"); $role-&gt;addChild("deleteItem"); ////create the owner role, and add the appropriate permissions, as well as both the reader and member roles as children $role=$this-&gt;_authManager-&gt;createRole("admin"); $role-&gt;addChild("reader"); $role-&gt;addChild("manager"); $role-&gt;addChild("createUser"); $role-&gt;addChild("updateUser"); $role-&gt;addChild("deleteUser"); echo 'Making Afnan admin'; $this-&gt;_authManager-&gt;assign('admin','3'); echo 'Making Riaz Manager'; $this-&gt;_authManager-&gt;assign('manager','2'); echo 'Sucess'; //provide a message indicating success echo "Authorization hierarchy successfully generated."; } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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