开发者

Zend Framework: How to edit the Error Controller to handle login required/auauthorized access errors?

i am creating a acl controller plugin that checks the if the user is author开发者_Python百科ized to the resource and redirect to the error controller to handle it. how do i go abt doing this?


Take a look at this question on SO: Help with Zend ACL.
Another good ACL/Auth tutorial can by found at devzone: Zend_Acl / Zend_Auth Example Scenario (The codelisting is incomplete but have a look at the comment "THE MISSING PIECES")

The important part is in the preDispatch Plugin:

$controller = $request->controller;
$action     = $request->action;
$module     = $request->module;
$resource   = $controller;

if (!$this->_acl->isAllowed($role, $resource, $action)) {
    if (!$this->_auth->hasIdentity()) {
        $module     = 'default';
        $controller = 'login';
        $action     = 'index';
    } else {
        $module     = 'default';
        $controller = 'error';
        $action     = 'privileges';
    }
}

$request->setModuleName($module);
$request->setControllerName($controller);
$request->setActionName($action);

If the is not logged in or has insufficient rights the request will be modified to forward to the Loginpage or the error controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜