2013-01-07 74 views
1


我正在使用zend導航來創建菜單。我想將默認類「活動」更改爲「選定」,我也想將該類添加到活動鏈接的錨點標記。 這裏是我已經把引導
如何在zend導航中更改子菜單活動類?

protected function _initNavigation() 
{ 

    $pages = array(
         array(
          'module' => 'admin', 
          'label' => 'Services', 
          'resource' => 'admin', 
          'controller' => 'services', 
          'pages' => array(
           array(
            'module'  => 'admin', 
            'label'   => 'Add Services', 
            'controller' => 'services', 
            'action'  => 'manage', 
            'route'   => 'default', 

            ), 
           array(
            'module'  => 'admin', 
            'label'   => 'View Services', 
            'controller' => 'services', 
            'action'  => 'view', 
            'route'   => 'default', 
            ), 
           ), 
          ) 
         ); 

      $this->bootstrap('layout'); 
      $layout = $this->getResource('layout'); 
      $view = $layout->getView(); 

    $config = new Zend_Config($pages); 
      $navigation = new Zend_Navigation($config); 
      $view->navigation($navigation); 
} 



在我看來,劇本在佈局我的示例代碼,我已經把這個下面的代碼

echo $this->navigation()->menu() 
         ->setUlId('menu'); 


電流輸出

<ul class="navigation" id="menu"> 
<li class="active"> 
    <a href="/test/public/admin/services">Services</a> 
    <ul> 
     <li> 
      <a href="/test/public/admin/services/manage">Add Services</a> 
     </li> 
     <li class="active"> 
      <a href="/test/public/admin/services/view">View Services</a> 
     </li> 
    </ul> 
</li> 


期望輸出

<ul class="navigation" id="menu"> 
<li> 
    <a href="/test/public/admin/services">Services</a> 
    <ul style='display:block;'> 
     <li> 
      <a href="/test/public/admin/services/manage">Add Services</a> 
     </li> 
     <li> 
      <a class='selected' href="/test/public/admin/services/view">View Services</a> 
     </li> 
    </ul> 
</li> 

回答

1

你必須只設置對象 '視圖' 註冊表以 '_initNavigation()' 末端在自舉方法。

Zend_Registry::set("view", $view); 

創建插件 'TestNavigation',在添加以下代碼

public function routeShutdown(Zend_Controller_Request_Abstract $request) 
{ 

    foreach (Zend_Registry::get('view')->navigation()->getPages() as $page) { 

      foreach ($page->getPages() as $subpage){      
       $uri = $subpage->getHref(); 
       if ($uri === $request->getRequestUri()) { 
        $subpage->setClass('selected'); 
       } 
      } 
    } 
} 

就是這樣,你做了。

+0

謝謝!有用 –

相關問題