Zend Navigation&递归Zend Acl

I would like to make navigation with Zend_Navigation based on Zend_Acl below is a piece of my navigation.xml file located in /application/configs dir

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <nav>
        <menu1>
            <label>solidData</label>
            <uri>#</uri>
            <pages>
                <service>
                    <label>menuLabel1</label>
                    <controller>service</controller>
                    <action>index</action>
                    <resource>service</resource>
                    <privilege>index</privilege>
                </service>
                <attendance>
                    <label>menuLabel2</label>
                    <controller>attendance</controller>
                    <action>index</action>
                    <resource>attendance</resource>
                    <privilege>index</privilege>
                </attendance>
            </pages>
        </menu1>
        <menu2>
            <label>systemData</label>
            <uri>#</uri>
            <pages>
                <users>
                    <label>users</label>
                    <controller>users</controller>
                    <action>index</action>
                    <resource>users</resource>
                    <privilege>index</privilege>
                </users>
                <profile>
                    <label>profiles</label>
                    <controller>profile</controller>
                    <action>index</action>
                    <resource>profile</resource>
                    <privilege>index</privilege>
                </profile>
                <dictionary>
                    <label>dictionary</label>
                    <controller>dictionary</controller>
                    <action>index</action>
                    <resource>dictionary</resource>
                    <privilege>index</privilege>
                </dictionary>
                <language>
                    <label>languages</label>
                    <controller>language</controller>
                    <action>index</action>
                    <resource>language</resource>
                    <privilege>index</privilege>
                </language>
            </pages>
        </menu2>
    </nav>
</config>

I dont want to show section which all pages are deny in ACL.

For example if there is user which has TYPE_DENY in ACL for all pages resource and privilege of <menu1> I dont want to create and display label "solidData"

The main problem is structure of my menu, because as you see I have various resources in one menu section.

I've try with my own Navigation class extending Zend_Navigation with function isVisible()" and "isActive()" but I cant find solution.

I'll be grateful for any help

[edit] Look at this fragment structure of my menu:

<menu2>
    <label>systemData</label>
    <uri>#</uri>
    <pages>
        <users>
            <label>users</label>
            <controller>users</controller>
            <action>index</action>
            <resource>users</resource>
            <privilege>index</privilege>
        </users>
        <profile>
            <label>profiles</label>
            <controller>profile</controller>
            <action>index</action>
            <resource>profile</resource>
            <privilege>index</privilege>
        </profile>
    </pages>
</menu2>

I cant <resource> to <menu2> because <menu2> include pages with different resources f.e. 'users' and 'profile'. maybe there is some possibility to add many resources to one menu. I try something like that:

<menu2>
    <label>systemData</label>
    <uri>#</uri>
    <resource>users</resource>
    <resource>profile</resource>
    <pages>
        ...
    </pages>
</menu2>

but i get

Invalid argument: $resource must be null, a string,  or an instance of Zend_Acl_Resource_Interface

EDIT

Ok, but if I change a structure of menu I also have to change ACL. In my ACL resource is Controller the privilege is Action in contoller.

php

2个回答

I'm not sure I understand correctly but why don't you have a resource in <menu1> and deny these users access to that resource either instead or additionally to the others? You may have to make changes to your ACL schema to catch such a events but not to the navigation.

UPDATE Try this for your second question:

<menu2>
    <label>systemData</label>
    <uri>#</uri>
    <resource>systemData</resource>
    <pages>
        ...
    </pages>
</menu2>

A resource is just an identifier so you should not (cannot) add two resources to one object. You do not have to worry about access logic in navigation but provide information for ACL to work with. In your ACL you have, of course, to add more logic so you can assign the privilege to the correct resource.

duanhaodi4809
duanhaodi4809 对不起我误会了。 好吧,如果您移动东西并根据您的设置和预期结果,您几乎总是需要更改ACL。 这是访问控制的本质,适用于多种类型的访问。 如果您将钱包从房间移动,只有您有钥匙并且只有您可以访问,另一个房间,您很可能必须在某处以某种方式进行更改以保护对钱包的访问。
接近 9 年之前 回复
dongronge3732
dongronge3732 我的意思是我想从<menu1>页面移动<service>到<menu2>的页面。 我不知道你的意思是“你不必在菜单结构中做出改变”
接近 9 年之前 回复
dongyinzheng6572
dongyinzheng6572 您不必更改菜单结构只需添加适当的资源名称,以便ACL可以找到匹配项。 您必须在ACL中进行更改才能找到正确的资源。 这个类似的问题可能有所帮助
接近 9 年之前 回复
dongxing7083
dongxing7083 好的,但如果我更改菜单结构,我还必须更改ACL。 在我的ACL资源中,Controller的权限是控制器中的Action
接近 9 年之前 回复
douren2395
douren2395 属于<menu2>的页面有不同的资源,所以我不能将任何资源添加到<menu2>这不是一个解决方案
接近 9 年之前 回复
duanlan8763
duanlan8763 我同意,为<menu1>添加资源和权限,并限制对ACL中该导航项的访问
接近 9 年之前 回复

i.e. Tag the privilege? maybe?

       $this->allow($guest, array('login', 'register'), array('view', 'guest:login', 'guest:register'));
   $this->allow('user', array('logout', new Zfcms_Acl_Resource_News, 'content'), array('view', 'browse', 'latest', 'submit', 'save', 'editown', 'deleteown'));
   $this->allow('admin', array('admin:area'), array('admin:view', 'admin:edit', 'admin:delete', 'admin:summary'));
   $this->allow('admin');
   $this->deny($guest, new Zfcms_Acl_Resource_News, array('save'));
   /**
    * The below prevents logged users from seeing the login/register tabs
    */
   $this->deny(new Zfcms_Acl_Role_User(), null, array('guest:login', 'guest:register'));
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问