Zend 导航和递归 Zend Acl

发布于 2024-11-24 20:43:17 字数 4537 浏览 2 评论 0原文

我想使用基于 Zend_Acl 的 Zend_Navigation 进行导航 下面是我的 navigation.xml 文件的一部分,位于 /application/configs 目录中,

<?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>

我不想显示 ACL 中所有页面都被拒绝的部分。

例如,如果有用户在所有页面资源的 ACL 中具有 TYPE_DENY 和 权限,我不想创建和显示标签“solidData”

主要问题是菜单的结构,因为如您所见,我在一个菜单部分中有各种资源。

我尝试使用我自己的导航类使用函数 isVisible()" 和 "isActive()" 扩展 Zend_Navigation,但我找不到解决方案。

我将不胜感激help

[编辑] 看看我的菜单的这个片段结构:

<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>

我不能 因为 包括具有“用户”和“个人资料”等不同资源的页面。 也许有可能将许多资源添加到一个菜单中。我尝试类似的操作:

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

但我得到

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

编辑

好的,但是如果我更改菜单结构,我还必须更改 ACL。 在我的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莳間冲淡了誓言ζ 2024-12-01 20:43:17

我不确定我是否理解正确,但为什么您在 中没有资源并拒绝这些用户访问该资源,或者拒绝其他用户访问该资源?您可能需要更改 ACL 架构才能捕获此类事件,但无需更改导航。

更新
尝试解决第二个问题:

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

资源只是一个标识符,因此您不应该(不能)将两个资源添加到一个对象。您不必担心导航中的访问逻辑,只需提供 ACL 可以使用的信息即可。当然,您必须在 ACL 中添加更多逻辑,以便可以将权限分配给正确的资源。

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.

风铃鹿 2024-12-01 20:43:17

即标记特权?或许?

       $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'));

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'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文