0

我不知道是什么问题,但是我尝试设置的导航菜单没有正确显示..

所有包含标签 <resource> 的导航页面都没有针对所有类型的用户类型(管理员、访客和成员)显示,知道为什么我会遇到这个问题吗?

这是我的 navigation.xml 文件的一部分:

<nav>
    <home>
        <label>Acceuil</label>
        <controller>index</controller>
        <action>index</action>
    </home>

    <contact>
        <label>Contact</label>
        <controller>index</controller>
        <action>contact</action>
        <resource>index</resource>
    </contact>

    <Categories>
        <label>Categories</label>
        <controller>index</controller>
        <action>categories</action>
    </Categories>

    <administration>
        <label>Administration</label>
        <controller>admin</controller>
        <action>index</action>
        <resource>admin</resource>
        <pages>
                <societes>
                    <label>Societes</label>
                    <controller>admin</controller>
                    <action>societes</action>
                    <resource>admin</resource>
                </societes>
        </pages>
    </administration>
</nav>

,我在 Bootstrap 中的 _initAcl :

$acl = new Zend_Acl();
    // add the roles
    $acl->addRole(new Zend_Acl_Role('guest'));
    $acl->addRole(new Zend_Acl_Role('user'), 'guest');
    $acl->addRole(new Zend_Acl_Role('admin'), 'user');

    // add the resources I have only two controller + Error
    $acl->add(new Zend_Acl_Resource('index'));
    $acl->add(new Zend_Acl_Resource('admin'));
    $acl->add(new Zend_Acl_Resource('error'));

    // set up the access rules
    $acl->allow(null, array('error'));
    // a guest can only read content and login
    $acl->allow('guest', 'index', array('contact', 'index', 'login', 'categories'));
    // users can also work with content
    $acl->allow('user', 'index', array('signaler', 'logout'));
    $acl->deny('user', 'index', array('inscription', 'login'));
    // administrators can do anything
    $acl->allow('admin', 'admin', array('index', 'categories', 'ajout-categorie', 'modifier-categorie', 'supprimer-categorie'));
    $acl->deny('admin', 'index', array('contact'));

    Zend_Registry::set('acl', $acl);

,我在 Bootstrap 中的 _initNavigation() :

protected function _initNavigation(){

    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();
    $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
    $container = new Zend_Navigation($config);

    $acl = Zend_Registry::get('acl');
    $auth = Zend_Auth::getInstance();

    if($auth->hasIdentity()) {
        $identity = $auth->getIdentity();
        $role = strtolower($identity->role);
    }else{
        $role = 'guest';
    }
    echo $role;
    $view->navigation($container)->setAcl($acl)->setRole($role);
}

还有我的 Acl 类:Application_Plugin_Acl

public function preDispatch(Zend_Controller_Request_Abstract $request){

    $this->acl = Zend_Registry::get('acl');
    // fetch the current user

    $auth = Zend_Auth::getInstance();

    if($auth->hasIdentity()) {
        $identity = $auth->getIdentity();
        $role = strtolower($identity->role);
    }else{
        $role = 'guest';
    }
    $controller = $request->controller;
    $action = $request->action;
    if (!$this->acl->isAllowed($role, $controller, $action)) {
        if ($role === 'guest') {
            $request->setControllerName('index');
            $request->setActionName('login');
        } else {
            $request->setControllerName('error');
            $request->setActionName('noauth');
        }
    }
}

我的 application.ini 中也有这个:指向 Acl 类

resources.frontController.plugins.acl = Application_Plugin_Acl

对不起,如果问题太长,但我在 Stack Overflow 上尝试了所有解决方案,但没有任何工作正常,并且

4

1 回答 1

0

我使用的允许和拒绝方法是错误的:

$this->allow('guest', 'index');
$this->deny('guest', array('signaler','logout'));

// cms users can also work with content
$this->allow('user', 'index');
$this->deny('user',array('inscription','login'));
// administrators can do anything
$this->allow('admin', 'admin');

$this->deny('admin','index',array('contact','about'));
于 2012-08-03T23:24:15.673 回答