1

这是我的导航 XML 格式,系统中有 2 个用户级别,管理员和超级管理员,

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

我的问题是,对于超级管理员,以及仪表板和统计信息,其他菜单项的标签(那些应该只为管理员显示)正在显示,是否有任何解决方法来隐藏标签。就我而言,除了仪表板外,顶级菜单项没有任何操作。

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

}

4

1 回答 1

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>

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

于 2012-09-12T11:39:38.337 回答