2012-04-15 59 views
0

我想實現Zend_Navigation - 此tutorialZend的導航問題與Zend_Config_Xml中

在引導文件創建菜單,麪包屑,

... 
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { 

    protected $_config; 
    protected $_layout; 

    protected function _initConfig() { 
     $this->_config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini'); 
     Zend_Registry::set("config", $this->_config); 
     if ($this->_config->debug) { 
      error_reporting(E_ALL | E_STRICT); 
      ini_set('display_errors', 'on'); 
     } 
     $request = new Zend_Controller_Request_Http(); 
     $uri = $request->getRequestUri(); 
     if (preg_match("/admin/", $uri)) { 
      //echo $this->_config->layout->admin->layout; exit; 
      $this->_layout = Zend_Layout::startMvc(
          array(
           'layoutPath' => $this->_config->layout->layoutPath, 
           'layout' => $this->_config->layout->admin->layout 
          ) 
      ); 
     } else { 
      $this->_layout = Zend_Layout::startMvc(
          array(
           'layoutPath' => $this->_config->layout->layoutPath, 
           'layout' => $this->_config->layout->layout) 
      ); 
      //echo $this->_view = $this->_layout->getView(); exit; 
     } 
    } 
    /** 
    * used for handling top-level navigation 
    * @return Zend_Navigation 
     */ 
    protected function _initNavigation() 
    { 
      $view = $this->_layout->getView(); 
      /* 
      $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); 

      $view->navigation($container); 
    } 
... 

下面還正在申請/ config中的navigation.xml文件夾

<?xml version="1.0" encoding="UTF-8"?> 
<configdata> 
    <nav> 
     <home> 
      <label>Home</label> 
      <uri>/</uri> 

      <pages> 
       <index> 
        <label>Home</label> 
        <uri>/index/index</uri>  
       </index> 
       <index> 
        <label>Product</label> 
        <uri>/index/product</uri>  
       </index> 

      </pages>   
     </home> 
    </nav> 
</configdata> 

在版式文件

... 
      <div class="breadcrumbs"> 
      <?= $this->navigation()->breadcrumbs()->setMinDepth(0)->setLinkLast(true)->setSeparator(" : "); ?> 
     </div> 
... 

,當我跑的網站,我得到了以下錯誤,

Fatal error: Uncaught exception 'Zend_Navigation_Exception' with message 'Invalid argument: Unable to determine class to instantiate' in C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php:235 Stack trace: #0 C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(117): Zend_Navigation_Page::factory(Array) #1 C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(164): Zend_Navigation_Container->addPage(Array) #2 C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(179): Zend_Navigation_Container->addPages(Array) #3 C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(852): Zend_Navigation_Container->setPages(Array) #4 C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(295): Zend_Navigation_Page->set('pages', Array) #5 C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(250): Zend_Navigation_Page->setOptions(Array) #6 C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(232): Zend_Navigation_Page->__construct(Array) #7 C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(117): Zend_Navigation_P in C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php on line 235

我搜索了計算器,以及谷歌的一些解決方案,但我找不到it.what我做錯了這個?請建議

+2

根據你有兩個節點,嘗試和重命名他們 – Ashley 2012-04-15 15:14:32

+0

@Ashley謝謝,現在錯誤已被修復 – mymotherland 2012-04-15 15:58:12

回答

1

我已經運行你的代碼。錯誤在配置中。你有兩個兄弟具有相同的名稱和當你看Zend_Mvc_Page線235你自己看着辦,爲什麼會拋出異常Zend_Config_Xml中它瑪吉這種形式

array 
    'label' => string 'Home' (length=4) 
    'uri' => string '/' (length=1) 
    'pages' => 
    array 
     'index' => 
     array 
      0 => 
      array 
       'label' => string 'Home' (length=4) 
       'uri' => string '/index/index' (length=12) 
      1 => 
      array 
       'label' => string 'Product' (length=7) 
       'uri' => string '/index/product' (length=14) 

 $hasUri = isset($options['uri']); 
     $hasMvc = isset($options['action']) || isset($options['controller']) || 
        isset($options['module']) || isset($options['route']); 

     if ($hasMvc) { 
      require_once 'Zend/Navigation/Page/Mvc.php'; 
      return new Zend_Navigation_Page_Mvc($options); 
     } elseif ($hasUri) { 
      require_once 'Zend/Navigation/Page/Uri.php'; 
      return new Zend_Navigation_Page_Uri($options); 
     } else { 
      require_once 'Zend/Navigation/Exception.php'; 
      throw new Zend_Navigation_Exception(
       'Invalid argument: Unable to determine class to instantiate'); 
     } 

因此,最終解決方案是更改第二個兄弟姐妹的名字。