2012-08-02 49 views
0
正常工作

我不知道是什麼問題,但我想設置導航菜單時,顯示不正確..我不能讓導航與Zend_Acl裏

所有導航包含標籤<資源>的頁面不會顯示所有類型的用戶類型(管理員,訪客和成員),任何想法爲什麼我有這個問題?

這是我的navigation.xml文件的一部分:在引導)

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

,我_initNavigation(:

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

,我_initAcl在引導

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 

對不起指出如果問題太長,但我想在這裏所有的解決方案堆棧溢出,但沒有什麼工作正常,並

+0

「所有的導航頁面包含無法顯示」:什麼? – conradfr 2012-08-03 09:55:00

+0

在navigation.xml文件中的標記,:$我很抱歉,我寫這個問題時太遲了.. – 2012-08-03 19:16:46

回答

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