Zend 模块特定的 ACL


Zend module specific ACL

在我的项目中大约有 5、6 个模块

Ex: Web - Public access, URL - www.abc.com
Admin - admin can access - admin.abc.com (Non Acl)
CP - Specific group can access - cp.abc.com (Non Acl)
pbo - Another group can access - pbo.abc.com (Acl based and implemented recently)

如上所述,我们最近添加了一个名为 PBO 的模块,基于 ACL 插件,

每个模块都有一个特定的引导程序文件,

但是在新模块实现之后,所有其他模块都在通过 ACL 插件并重定向到 PBO 模块的默认页面。

这就是权限的设置方式

$this->acl->allow('superAdmin', 'user', array('login','logout'));
$this->acl->allow('superAdmin', 'index', 'index');
$this->acl->allow('superAdmin', 'app', 'index');
$this->acl->allow('admin', 'user', array('index','login','logout','registered'));      
$this->acl->allow('admin', 'index', 'index');
$this->acl->allow('admin', 'app', array('index', 'do-feature', 'do-delete'));

引导程序中初始化 ACL

public function _initAcl()
{
    //Omit the process in CLI mode
    if (php_sapi_name() != 'cli') 
    {        
        $helper = new Nexva_Controller_Action_Helper_AclPbo();
        $helper->setRoles();
        $helper->setResources();
        $helper->setPrivilages();
        $helper->setAcl();
        //Register the ACL plugin - Then it will be called automatically,whenever an     acion is called
        $frontController = Zend_Controller_Front::getInstance(); 
        $frontController->registerPlugin(new Nexva_Plugin_AclPbo());
    }
}

有没有办法避免在其他模块中调用PBO模块的ACL?

这是 Zend Framework 1 的一个问题。

始终为任何给定模块调用和执行所有模块的引导程序。 这就是Zend Framework的设计方式。

由于这个问题,有一篇非常好的文章可以帮助理解模块引导在 ZF 中的工作原理及其缺点。 它是由Matthew Weier O'Phinney撰写的:

http://mwop.net/blog/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html

从那里,这个站点有一个教程,讨论了如何设置特定于模块的"新"Bootstrap 类似层的解决方案。 它还链接到他们提取的几个来源,其中大部分都值得一读(是的,有相当多的阅读)。

http://offshootinc.com/blog/2011/02/11/modul-bootstrapping-in-zend-framework/

我希望这有所帮助!

您可以做的一件事是在注册插件之前检查当前模块是否为 PBO

if($frontController->getRequest()->getModuleName() == 'PBO')
$frontController->registerPlugin(new Nexva_Plugin_AclPbo());