I have created a user authentication system u开发者_运维技巧sing cakephp's aco/aro tables using this tutorial.
I am now creating an interface to change the groups of users and display the current group of the user.
I searched the API and could not find a built-in method to query the group that a user belongs to. What is the best way to do this?
You may or may not decide to do this but in my users
table I have a security_group_id
field that points to a security_groups
table. Within this security_groups
table I store the aliases/names of the security groups (i.e. Administrators, Site Users, Managers, etc.).
In the aro
table these security groups are root/parent nodes for all the subsequent user accounts that I create on the system. Thus by querying my users
tables security_group_id
field, I can determine the group that the user is in.
Another approach would be to do:
$aro =& ClassRegistry::init('Aro');
$theUser = array('User' => array('id' => <user_id>));
$aroPath = $aro->node($theUser);
$aroPath
will be an array including the user node in the $aro
table as well as any and all parent nodes.
精彩评论