Need help for authManager

Hi all,

I’m reading the document http://www.yiiframework.com/doc/guide/topics.auth, but have following questions for authManager:

  1. In the config file:



'authManager'=>array(

   'class'=>'CDbAuthManager',

   'connectionID'=>'db',

),



but, what’s the real difference between ‘CDbAuthManager’ and ‘CPhpAuthManager’?




$auth=Yii::app()->authManager; 

$auth->createOperation('createPost','create a post');

$auth->createOperation('readPost','read a post');

$auth->createOperation('updatePost','update a post');

$auth->createOperation('deletePost','delete a post');



Where we should add these codes to, in a controller?

  1. can we add some complex logic codes in $bizRule?

1: ‘CDbAuthManager’ is storing the info in a database and ‘CPhpAuthManager’ you use for storing the info in a PHP file.

2: If you are using it with a database, you would put it in a controller and run that controller/action just once. If you are using the PHP-file, you would configure the CPhpAuthManager with the ‘authFile’ property, which is a url pointing to your file.

3: I think you can put any PHP-code in the bizRule.

Hi Komodo,

Thank you very much for the comments.

So when set as "CDbAuthManager", I need to create some tables in db to store the rules, if then what is the structure for these tables, or are there some examples can help?

I’m sorry I could not understand you mentioned “run that controller/action just once”




$auth=Yii::app()->authManager; 

$auth->createOperation('createPost','create a post');

$auth->createOperation('readPost','read a post');

$auth->createOperation('updatePost','update a post');

$auth->createOperation('deletePost','delete a post');



Do it mean that I place these codes in some controller, and run the action, the auth table will be created automatically and next time the system will check the privilege automatically according to the controller’s function accessRules?

Actually, I have two tables now:

  1. "User_detail" - the user base information stored here

  2. "User_type" e.g. "admin","power user","normal user"

And I want to create some codes with authManager that when a new user created we can tell if he/she has the enough privilege to enter current section.

Here the users are not static, they can be created via registration or removed by administrator. Which one (CPhpAuthManager or CDbAuthManager) do you think is the best choice?

I always use CDbAuthManager because I like to check with phpmyadmin the users, even before create an interface.

The example of table structure are in framework/web/auth/schema.sql, that means that in your local instance of framework you can find this sql specification. (is explained in CDbAuthManager).

What Komodo means is that you can create a actionTemp() in some controller with the code for create the operation, than call this action (that will save in db the operation) and finally remove this action from the controller.

After that you can do Yii::app()->authManager->assign() or revoke() for the newly created operations

Hi zaccaria,

Thank you very much.

I have figure this logic out. Now I’m using the CPhpAuthManager.

But one problem now, I’m puzzled with bizRule.

e.g. see the following codes in some example:



return Yii::app()->user->id==$params["post"]->authID;

What’s the $params[“post”] means? Can I say $params[“post”]->authID is $_POST[‘authID’]?

Very appreciate~