2012-04-15 9 views
0

Ich versuche Zend_Navigation zu implementieren - Erstellen eines Menüs und Paniermehl dieses tutorialzend Navigation Ausgabe mit Zend_Config_Xml

In Bootstrap-Datei,

... 
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); 
    } 
... 

Auch unten ist die navigation.xml unter Anwendung/config Ordner

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

im Layout-Datei

, wenn ich die Seite lief, bekam ich folgende Fehlermeldung,

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

ich auf Stackoverflow gesucht sowie Google mit einiger Lösung, aber ich konnte nicht finden it.what i auf diese falsch gemacht? Mit freundlichen Grüßen

+2

Unter haben Sie zwei Knoten, versuchen Sie und benennen Sie sie um – Ashley

+0

@Ashley Danke, jetzt wurde der Fehler behoben – mymotherland

Antwort

1

Ich habe Ihren Code ausgeführt. Fehler ist in der Konfiguration. Sie haben zwei Geschwister mit dem gleichen Namen und Zend_Config_Xml es

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) 

dieser Form marge Wenn Sie an Zend_Mvc_Page Linie 235 sehen Sie herausfinden können, warum Ausnahme ausgelöst.

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

Also endlich die Lösung ist den Namen der zweiten Geschwister zu ändern.