0

I am trying to implement Zend_Navigation – creating a menu, and breadcrumbs by this tutorial

In Bootstrap file,

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

Also below is the navigation.xml under application/config folder

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

In Layout file

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

when i ran the site, i got the following error,

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

I searched on stackoverflow as well as google with some solution, but i could not find it.what i done wrong on this ? Kindly advice

mymotherland
  • 7,968
  • 14
  • 65
  • 122

1 Answers1

1

I've run yours code. Bug is in config. You have two siblings with the same name and Zend_Config_Xml marge it to this form

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)

When you look at Zend_Mvc_Page line 235 you can figure why exception is thrown.

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

So finally the solution is change the second siblings name.

Artur Michalak
  • 459
  • 3
  • 6