Zend Framework ACL角色和模块

Dre*_*ton 3 acl zend-framework

我试图区分我的管理模块中的索引控制器和索引操作以及使用ACL在我的默认模块中的索引控制器和索引操作.

我希望登录的用户能够访问默认模块的索引控制器,但根本不能访问管理模块.无论我尝试什么,如果我允许访问默认模块的索引,管理模块索引也可用.

任何建议将不胜感激.谢谢

Opt*_*mus 5

定义您的资源module-controller和特权,action然后您就可以拥有这样的东西

...

// Default module, index controller
$this->addResource(new Zend_Acl_Resource('default-index')); 
// Admin module, index controller
$this->addResource(new Zend_Acl_Resource('admin-index'));

// Allow user to access default module, index controller, index and about actions
$this->allow('user', 'default-index', array('index', 'about'));
// Allow admin to access admin module, index controller, all actions
$this->allow('admin', 'admin-index');

...
Run Code Online (Sandbox Code Playgroud)

[编辑]并在您的控制器插件predispatch

    ...

    $module = $request->getModuleName();
    $controller = $request->getControllerName();
    $action = $request->getActionName();
    $resource = "{$module}-{$controller}";
    if ($acl->has($resource)) {
        if (!$acl->isAllowed($role, $resource, $action)) {
        }
    }
    ...
Run Code Online (Sandbox Code Playgroud)