无法基于Zend_Acl创建导航 [英] Could not create navigation based on Zend_Acl

查看:68
本文介绍了无法基于Zend_Acl创建导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习使用Zend_Acl创建导航. 但是导航只显示给管理员,没有其他人显示.

I am trying to learn to create navigation with Zend_Acl. But the navigation only displays for admin and no one else.

我已经阅读了我的代码,并尝试跟踪ZendFramework随附的代码.但是我被困住了,无法弄清楚自己在做什么错.

I have read through my code and I tried to trace the code that comes with ZendFramework. But I am stuck and I can't figure out what I am doing wrong.

这是我的ACL班级:

class Application_Model_LibraryACL extends Zend_Acl
{
    public function __construct()
    { 
            $this->add(new Zend_Acl_Resource( 'guestbook' ) );
            $this->add( new Zend_Acl_Resource( 'index' ) );

            $this->add(new Zend_Acl_Resource( 'error' ) );
            $this->add(new Zend_Acl_Resource( 'authentication' ) );
            $this->add(new Zend_Acl_Resource( 'login' ), 'authentication' );
            $this->add(new Zend_Acl_Resource( 'logout' ), 'authentication' );

            $this->addRole( new Zend_Acl_Role( 'guest' ) );
            $this->addRole( new Zend_Acl_Role( 'member' ), 'guest' );
            $this->addRole( new Zend_Acl_Role( 'admin' ), 'member' );

            $this->allow( 'guest', 'error', 'error' );
            $this->allow( 'guest', 'index', 'index' );
            $this->allow( 'guest', 'authentication', array( 'login', 'logout' ) );
            $this->allow( 'member', 'guestbook', 'sign' );
            $this->allow( 'admin' );
    } 
}

这是定义导航的xml文件:

Here is the xml file that defines the navigation:

<?xml version="1.0" encoding="utf-8"?>
<config>
    <nav>
            <home>
                    <label>Home</label>
                    <controller>index</controller>
                    <action>index</action>
                    <resource>index</resource>
            </home>

            <logout>
                    <label>Logout</label>
                    <controller>authentication</controller>
                    <action>logout</action>
                    <resource>logout</resource>
            </logout>

            <login>
                    <label>Login</label>
                    <controller>authentication</controller>
                    <action>login</action>
                    <resource>login</resource>
            </login>

            <guestbook>
                    <label>Guestbook</label>
                    <resource>guestbook</resource>
                    <uri></uri>
                    <pages>
                            <list>
                                    <label>List</label>
                                    <controller>guestbook</controller>
                                    <action>index</action>
                                    <resource>guestbook</resource>
                            </list>
                            <sign>
                                    <label>Sign</label>
                                    <controller>guestbook</controller>
                                    <action>sign</action>
                                    <resource>guestbook</resource>
                            </sign>
                    </pages>
            </guestbook>


    </nav>

这是引导文件中设置导航的代码:

And here is the code in the bootstrap file that sets up the navigation:

$navContainerConfig = new Zend_Config_Xml( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
$navContainer = new Zend_Navigation( $navContainerConfig );
$view->navigation( $navContainer )->setAcl( $this->acl )->setRole( Zend_Registry::get( 'role' ) );

$ this-> acl保存acl对象,而zend注册表保存已登录用户的角色.

$this->acl holds the acl object and zend registry holds the role of the logged in user.

请问您可能有任何疑问.我已经被完全卡住了超过3天.

please ask any question you might have. I have been completely stuck for over 3 days.

推荐答案

我所看到和关注的是两件事.

What I see and concerns me are two things.

首先是一个名为"guestbook"的资源被使用了3次.我不认为这是您的问题,但您应该解决该问题.

First is a resource named "guestbook" is used three times. I don't think this is your problem but you should fix that.

第二,您的问题是,allow中的第三个参数是$ privileges.我不确定我现在在说什么,但导航不需要特权.不过,最肯定不是您提供的.

Second, and your problem, the third argument in allow are $privileges. I'm not certain about what I'm saying now but navigation does not require privileges. Most certainly not the ones you've provided, though.

因此,请尝试以下操作:

So, try just this:

$this->allow( 'guest', 'error' );
$this->allow( 'guest', 'index' );
$this->allow( 'guest', 'authentication');
$this->allow( 'member', 'guestbook' );
$this->allow( 'admin' );

这篇关于无法基于Zend_Acl创建导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆