开发者

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

  1. 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()));

  2. Use sfWidgetFormChoice

  3. Use sfGuardSecurityUser::getGroups ($user->getGroups) to set choices for sfWidgetFormChoice widget. Here $user is instance of myUser>sfGuardSecurityUser
  4. Do not forget validator
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜