小编Nev*_*oxx的帖子

zfcuser在注册后添加用户角色

我正在使用Zend Framework 2和ZfcUser,BjyAuthorize和Doctrine作为数据库.到目前为止,注册等工作非常顺利.我的问题是,注册用户没有分配角色,所以我想在注册期间向用户添加角色"user".

我想我可以将它附加到"注册"事件,但我不知道该怎么做.

我希望有一个人可以帮助我 ...

(我使用本教程设置zfcuser等http://samminds.com/2013/03/zfcuser-bjyauthorize-and-doctrine-working-together/)

public function onBootstrap(MvcEvent $e)
{
    $zfcServiceEvents = $e->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager();
    $zfcServiceEvents->attach('register', function($e) {
        $user = $e->getParam('user');
        // probably the role must be added here, with $user->addRole();
        // but how do i get the user Role Entity to add from DB?

});
Run Code Online (Sandbox Code Playgroud)

zend-framework doctrine-orm zfcuser bjyauthorize

5
推荐指数
2
解决办法
3246
查看次数