Yii Framework Forum: Need help for authManager - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need help for authManager Rate Topic: ***** 1 Votes

#1 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 01 June 2010 - 10:02 PM

Hi all,

I'm reading the document http://www.yiiframew...ide/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'?

2.
$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?

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

#2 User is offline   Theill11 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 03-March 10
  • Location:@ localhost

Posted 02 June 2010 - 12:49 AM

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

#3 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 02 June 2010 - 01:45 AM

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?
0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 02 June 2010 - 07:07 AM

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
0

#5 User is offline   zbq 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 27-May 10

Posted 02 June 2010 - 10:12 PM

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~
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users