Zend Framework ACL 角色和模块

发布于 2025-01-01 06:36:47 字数 162 浏览 1 评论 0原文

我试图使用 ACL 来区分管理模块中的索引控制器和索引操作以及默认模块中的索引控制器和索引操作,我简直要发疯了。

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

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

I am going insane trying to distinguish between the Index controller and Index action in my Admin Module and the Index controller and Index action in my Default module using ACL.

I want logged in users to be able to have access to the Default Module's index controller but not the admin module at all. No matter what I try, if I allow access to the default module's index, the admin modules index is available as well.

Any suggestions would be greatly appreciated. Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素年丶 2025-01-08 06:36:47

将您的资源定义为 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');

...

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

    ...

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

Define your resources as module-controller and privileges as action then you can have something like this

...

// 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');

...

[EDIT] And in your controller plugin predispatch

    ...

    $module = $request->getModuleName();
    $controller = $request->getControllerName();
    $action = $request->getActionName();
    $resource = "{$module}-{$controller}";
    if ($acl->has($resource)) {
        if (!$acl->isAllowed($role, $resource, $action)) {
        }
    }
    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文