我想知道使用Zend_Acl显示/隐藏部分视图的方式是什么?我想我会的
创建一个Controller插件,用于将登录的用户+ acl传递给视图
$this->view->loggedInUser = Zend_Auth::getIdentity();
$this->view->acl = Zend_Registry::get('acl');
Run Code Online (Sandbox Code Playgroud)然后在视图脚本中做类似的事情
$this->acl->isAllowed($this->view->loggedInUser, 'resource', 'privilege');
Run Code Online (Sandbox Code Playgroud)或者,还有更好的方法?或者我应该使用View Helper?返回一个布尔值是否允许登录用户?
我想添加错误处理module.php以在Flash Messenger中添加所有错误消息并重定向到特定页面(根据我的要求):
public function handleError(MvcEvent $e) {
$exception = $e->getParam('exception');
$controller = $e->getTarget();
//echo $exception->getMessage(); exit;
if (!$e->getApplication()->getServiceManager()->get('AuthService')->hasIdentity()) {
$controller->flashMessenger()->addErrorMessage("Session Expired..!!");
return $e->getTarget()->plugin('redirect')->toRoute('auth', array('action' => 'login'));
}
switch ($exception->getCode()) {
case "2003" :
$controller->flashMessenger()->addErrorMessage("Unable to connect database..!!");
break;
default :
$controller->flashMessenger()->addErrorMessage($exception->getMessage());
break;
}
$e->getApplication()->getServiceManager()->get('AuthService')->clearIdentity();
return $e->getTarget()->plugin('redirect')->toRoute('auth', array('action' => 'login'));
}
Run Code Online (Sandbox Code Playgroud)
但是在某些错误中,它会抛出对未定义方法插件的调用,$e->getTarget()因为在某些情况下,错误是在插件绑定之前生成的。我想要一种redirect and flash messenger plugins无需引用任何控制器即可访问的方法。