sfDoctrineGuard - get only groups logged in user is a member of
I have a table that has a sfGuardGroup colum开发者_如何学运维n so when a user logs in, they can only see the records users in their group have made.
When creating a record I want to have a select box for the sfGuardGroup that only contains the groups that the logged in user is a member of.
Anyone know how to do this please?
Thanks
In the form::configure
get user: use sfContex::getInstance()->getUser() (easy way, not recommend) or inject sfUser from controller as option
$this->form = new myAwesomeUserForm(array(),array('user'=>$this->getUser()));
Use sfWidgetFormChoice
- Use sfGuardSecurityUser::getGroups ($user->getGroups) to set choices for sfWidgetFormChoice widget. Here $user is instance of myUser>sfGuardSecurityUser
- Do not forget validator
精彩评论