doutusheng5879 2011-07-19 13:04
浏览 42

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.

  • 写回答

2条回答 默认 最新

  • douxingti9307 2011-07-19 14:59
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?