Yii Framework Forum: Set A Role To User Programmatically - Yii Framework Forum

Jump to content

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

Set A Role To User Programmatically without RBAC Rate Topic: -----

#1 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 20 November 2012 - 09:01 AM

Hi, how to set a custom role for user on UserIdentity class?

I want to set a role when "authenticate" function authedicate the user.

I have write in function the $this->setState('roles', 'admin');
and in accessRules() of Controller the 'roles'=>'myauth' but not work

Any suggestion?
Thanks
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 20 November 2012 - 08:33 PM

I found out that $this->setState('roles', 'admin') is not appropriate method to set a role to user

So, how can I set a role to the current user?
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 21 November 2012 - 03:46 AM

Why do you wish to do it dynamically? You must already be using some sort of hard coded logic to determine which user gets which roles.
0

#4 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 21 November 2012 - 07:33 AM

View PostKeith, on 21 November 2012 - 03:46 AM, said:

Why do you wish to do it dynamically? You must already be using some sort of hard coded logic to determine which user gets which roles.


Hi Keith, thank you for responsing :)

In my system I have two type of users 'editor' and 'author'.
So I want to check if a user has the permissions for each controller/action using in accessRules the 'role'=>'editor' or 'role'=>'author'.

I dont want to use AR for users because there are only few users stored in php file as array
So how can I set a simple role for the user like $user->addRole('author') ?

Thank you
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#5 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,451
  • Joined: 04-March 10
  • Location:UK

Posted 21 November 2012 - 07:49 AM

If you want to avoid using the database, you could consider CPhpAuthManager, which will persist your role assignments to the file system. I don't think there's a built in way to persist to just the user's session, which is what you seem to be suggesting.

I'd suggest configuring your auth file using the class above and let it handle the RBAC thereafter, rather than trying to do it all dynamically.

EDIT:
Useful article.
0

#6 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,305
  • Joined: 21-February 11
  • Location:Greece

Posted 21 November 2012 - 05:04 PM

View PostKeith, on 21 November 2012 - 07:49 AM, said:

If you want to avoid using the database, you could consider CPhpAuthManager, which will persist your role assignments to the file system. I don't think there's a built in way to persist to just the user's session, which is what you seem to be suggesting.

I'd suggest configuring your auth file using the class above and let it handle the RBAC thereafter, rather than trying to do it all dynamically.

EDIT:
Useful article.


Ok Keith, I will try it in this way
Thanks :)
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
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