這是我的導航XML格式的,也有在系統中,管理員和超級管理員2個用戶級別,Zend的導航渲染問題
當作爲管理所有的菜單項應顯示登錄和它工作得很好,超級僅管理員應顯示儀表板和統計信息。
我的問題是,對於超級管理員,以及儀表板和統計信息,其他菜單項(只應顯示給管理員)的標籤正在顯示,是否有任何解決辦法來隱藏標籤。在我的情況下,頂層菜單項沒有任何操作,除了儀表板。
菜單與Zend的ACL連接
<configdata>
<nav>
<dashboard>
<label>Dashboard</label>
<class>nav-top-item no-submenu</class>
<controller>index</controller>
<action>index</action>
<resource>index</resource>
<privilege>index</privilege>
</dashboard>
<app>
<label>Apps</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<managefeaturedapps>
<label>Manage Apps</label>
<controller>app</controller>
<action>index</action>
<resource>app</resource>
<privilege>index</privilege>
</managefeaturedapps>
<managepage>
<label>Filter Apps</label>
<controller>app</controller>
<action>filter-apps</action>
<resource>app</resource>
<privilege>filter-apps</privilege>
</managepage>
</pages>
</app>
<user>
<label>Users</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<allusers>
<label>Registered Users/Developers</label>
<controller>user</controller>
<action>index</action>
<resource>user</resource>
<privilege>index</privilege>
</allusers>
</pages>
</user>
<page>
<label>Pages</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<addpage>
<label>Add New Page</label>
<controller>page</controller>
<action>add-page</action>
<resource>page</resource>
<privilege>add-page</privilege>
</addpage>
</pages>
</page>
<statistics>
<label>Statistics</label>
<class>nav-top-item no-submenu</class>
<uri>#</uri>
<pages>
<viewstats>
<label>Statistics</label>
<controller>statistic</controller>
<action>index</action>
<resource>statistic</resource>
<privilege>index</privilege>
</viewstats>
</pages>
</statistics>
</nav>
ACL代碼
class XXX_Controller_Action_Helper_AclPbo {
public $acl;
//Instatntiate Zend ACL
public function __construct()
{
$this->acl = new Zend_Acl();
}
//Set User Rolse
public function setRoles()
{
$this->acl->addRole(new Zend_Acl_Role('superAdmin'));
$this->acl->addRole(new Zend_Acl_Role('admin'));
}
//Set Resources - controller, models, etc...
public function setResources()
{
$this->acl->add(new Zend_Acl_Resource('app'));
$this->acl->add(new Zend_Acl_Resource('index'));
$this->acl->add(new Zend_Acl_Resource('user'));
$this->acl->add(new Zend_Acl_Resource('page'));
$this->acl->add(new Zend_Acl_Resource('statistic'));
}
//Set privileges
public function setPrivilages()
{
$this->acl->allow('superAdmin', 'user', array('login','logout'));
$this->acl->allow('superAdmin', 'index', 'index');
$this->acl->allow('superAdmin', 'app', 'index');
$this->acl->allow('superAdmin', 'statistic', array('index'));
$this->acl->allow('admin', 'user', array('index','login','logout'));
$this->acl->allow('admin', 'index', 'index');
$this->acl->allow('admin', 'app', array('index'));
$this->acl->allow('admin', 'page', array('index', 'add-page', 'edit-page'));
$this->acl->allow('admin', 'statistic', array('index'));
}
//Set ACL to registry - store ACL object in the registry
public function setAcl()
{
Zend_Registry::set('acl', $this->acl);
}
}
您還需要顯示ACL代碼 – PatrikAkerstrand
admin和superAdmin具有幾乎相同的ACL規則可以嗎? – akond
@akond - 修改它。 – Shaolin