在 View 中使用 Zend_Acl 来显示/隐藏部分视图的方法是什么 [英] Whats the way to use Zend_Acl in View to show/hide parts of view
本文介绍了在 View 中使用 Zend_Acl 来显示/隐藏部分视图的方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道使用 Zend_Acl 显示/隐藏部分视图的方法是什么?我想我会
I am wondering whats the way to use Zend_Acl to show/hide parts of view? I am thinking I will
创建一个Controller Plugin,通过登录用户+ acl查看
Create a Controller Plugin that passes the logged in user + acl to view
$this->view->loggedInUser = Zend_Auth::getIdentity();
$this->view->acl = Zend_Registry::get('acl');
然后在视图脚本中执行类似
Then in view scripts do something like
$this->acl->isAllowed($this->view->loggedInUser, 'resource', 'privilege');
或者有更好的方法吗?还是应该使用视图助手?返回一个布尔值是否允许登录用户?
Or is there a better way? Or should I use a View Helper? That returns a boolean whether the logged in user is allowed?
推荐答案
你在视图中使用它,所以对我来说 ViewHelper 是正确的地方 - 我已经这样做过一次:
You are using it in the view, so for me ViewHelper is correct place for that - I've done it once that way:
class Zend_View_Helper_HasAccess extends Zend_View_Helper_Abstract
{
private $_acl;
public function hasAccess($role, $controller, $action)
{
if (!$this->_acl) {
$this->_acl = Zend_Controller_Front::getInstance()->getPlugin('Acl');
//In yout case registry, but front controller plugin is better way to implement ACL
}
return $this->_acl->isAllowed($role, $controller, $action);
}
}
这篇关于在 View 中使用 Zend_Acl 来显示/隐藏部分视图的方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文