Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii framework : role based access control

Tags:

php

yii

I am implementing role based access control using yii framework for the application mentioned in the Agile web application development using yii framework book.I have implemented every thing up to page number 189.

page number 189 says that following method can be used to check whether user is allowed to perform some action or not.

If( Yii::app()->user->checkAccess('createIssue')) { //perform needed logic }

but this method always return false for users who have been assigned to createIssue operation

following is the database diagram for RBAC

enter image description here

i am linking UserID and role for authassignment table using following command.

$auth=Yii::app()->authManager; $auth->assign('member',1);

As you can see my user table and authassignment table does not have direct relationship.

And i have configured main.php file in configuration folder

These are the all we have done so far and could any body share your knowledge with me if any thing is missing here. Thanks in advance for any help.

like image 697
KItis Avatar asked Jan 13 '12 08:01

KItis


People also ask

What is Yii framework used for?

Yii is a high-performance, component-based PHP framework for developing large-scale Web applications rapidly. It enables maximum reusability in Web programming and can significantly accelerate your Web application development process.

What is difference between Yii and Yii2?

Conceptually Yii1 and Yii2 are quite similar, however Yii2 runs on newer PHP versions and utilizes namespaces, traits etc. Yii2 has also support for dependency injection through $container singleton available after initializing the framework.

What is RBAC in Yii2?

Yii2-RBAC provides a web interface for advanced access control and includes following features: Allows CRUD operations for roles, permissions, rules. Allows to assign multiple roles or permissions to the user. Allows to create console migrations.


1 Answers

Come on, man! Of course there must be a direct relationship between users and assigments. In the following piece of code:

$auth=Yii::app()->authManager; $auth->assign('member',1)

'member' belongs to authiments, and '1' is the id of the user being assigned with that role. "userid", in the "authassigment" table, must point to users table.

like image 112
Alfredo Castaneda Garcia Avatar answered Oct 10 '22 18:10

Alfredo Castaneda Garcia