Zend导航渲染问题

时间:2012-09-11 12:53:18

标签: zend-framework zend-navigation zend-acl

这是我的导航XML格式,系统中有2个用户级别,Admin和Super Admin,

当以管理员身份登录时,应显示所有菜单项并且工作正常,对于超级管理员,仅显示仪表板和统计信息。

我的问题是,对于超级管理员,以及仪表板和统计信息,其他菜单项的标签(应仅显示给管理员)显示,是否有任何工作来隐藏标签。在我的情况下,顶级菜单项没有任何操作,除了仪表板。

菜单与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);
}

}

1 个答案:

答案 0 :(得分:1)

您遇到此行为的原因在于

<statistics>
    <label>Statistics</label>
    <class>nav-top-item no-submenu</class>
            <uri>#</uri>

,而你应该

<statistics>
    <label>Statistics</label>
    <class>nav-top-item no-submenu</class>
    <controller>statistic</controller>
    <action>index</action>
    <resource>statistic</resource>
    <privilege>index</privilege>

只要您没有定义资源的访问参数,任何人都可以使用它。