Zend_Auth updating Identity

时间:2015-09-14 15:21:55

标签: zend-framework zend-auth

I'm now sitting here a little bit longer and i want to know the best solution to update the Identity from the Zend_Auth.

public function _initLoadSessionData() {
    if (Zend_Auth::getInstance()->hasIdentity()) {
        $userTbl = new Application_Model_User();
        $userData = $userTbl->getUserData(Zend_Auth::getInstance()->getIdentity()->ID);

        $zendAuth = Zend_Auth::getInstance()->getIdentity();

        foreach ($userData as $key => $value) {
            $zendAuth->$key = $value;
        } 
    }
}

This is the first try i did and it works very well. I put this function into the Bootstrap but I'm sure that this solution is very bad (e.g. performance) because it updates every time. The problem is, that i want to update the Zend_Acl Roles and it needs to be updated instantly. Thanks for your help guys! :)

1 个答案:

答案 0 :(得分:0)

你应该使用插件。

创建一个扩展Zend_Controller_Plugin_Abstract并实现preDispatch方法的类。 在其中,您可以检查ACL上的更新,并将请求重定向到另一个控制器/操作,如果不允许的话。

别忘了在Bootstrap.php上注册插件

Zend_Controller_Front::getInstance()->registerPlugin(new My_Plugin());