Zend_Acl中采用模块化结构?
-
12-09-2019 - |
题
我创建与Zend一个MVC通过读取 HTTP://框架.zend.com /手动/ EN / zend.controller.modular.html 。
的问题是,我无法找到一种方法,使用与Zend_Acl就模块化结构。 Zend_Acl里根本没有添加模块的方法。它只允许我补充控制器和动作。
我如何使用Zend_Acl中采用模块化structrue?它甚至有可能与Zend框架?
的当前版本解决方案
有绝对是。这就是我们在我们的项目做。我们验证URI路径($request->getPathInfo()
),如:/admin/user/edit
。这里的“管理”是一个模块,“用户”是控制器,和“编辑”是一个动作。而且我们有一个访问插件:
class Our_Application_Plugin_Access extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request) {
foreach (self::current_roles() as $role) {
if (
Zend_Registry::get('bootstrap')->siteacl->isAllowed(
$role,
$request->getPathInfo()
)
) return;
}
$this->not_allowed($request);
}
...
}
注册在的application.ini:
resources.frontController.plugins.access = "Our_Application_Plugin_Access"
其他提示
其他选项,伊万的是设置的资源,而不是仅仅“控制器”,以某事。像“模块控制器”。
这是可能的,我每次都使用它。 首先,请记住的该Zend_Acl里将验证该资源是一个任意实体(字符串)下,没有必要与特定模块或控制器。它可以是字符串“hello”,并在你的程序,你可以检查用户是否可以访问该资源的“hello”。我经常使用的一些任意的资源为“登录按钮”,“注销按钮”,以显示在Zend_Navigation的链接。
在你的情况下,应该定义资源(在ACL),其一些字符串可以映射到一个模块/控制器的布局。 例如,对于该模块foo和控制器栏定义资源“foo.bar”。比访问检查过程中,您会读模块和控制器的名称和一个字符串合并他们获得的资源。
在一个实施例之实践:
class Application_Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract {
...
public function preDispatch(Zend_Controller_Request_Abstract $request){
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
...
$resource = $module . '.' . $controller; //we create the custom resource according to the model we have defined
...
$role=NULL;
if($this->_auth->hasIdentity()){
$identity = $this->_auth->getStorage()->read(); //depending on your implementation
$role = $identity->role; //depending on your implementation
}
...
if(!$this->_acl->isAllowed($role, $resource, $action)){
//deny access
}
//allow access
}
}
不隶属于 StackOverflow