views:

197

answers:

1

Hi,

I've been struggling with Zend_Navigation all weekend, and now I have another problem, which I believe has been the cause of a lot of my issues.

I am trying to add Zend_Navigation to a legacy 1.7.6 Zend Framework application, i've updated the Zend Library to 1.9.0 and updated the bootstrap to allow this library update.

The problem is that I don't know how, and the examples show the new bootstrap method of how to add the Navigation object to the view, I've tried this:

//initialise the application layouts with the MVC helpers
$layout = Zend_Layout::startMvc(array('layoutPath' => '../application/layouts'));

$view = $layout->getView();
$configNav = new Zend_Config_Xml('../application/config/navigation.xml', 'navigation');
$navigation = new Zend_Navigation($configNav);
$view->navigation($navigation);
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view); 

This seems to run through fine, but when I go to use the breadcrumb view helper in my layout, it errors with: Strict Standards: Creating default object from empty value in C:\www\moobia\development\website\application\modules\employers\controllers\IndexController.php on line 27

This is caused by the following code in the init() function of my controller.

$uri = $this->_request->getPathInfo();
$activeNav = $this->view->navigation()->findByUri($uri); <- this is null when called
$activeNav->active = true;

I believe it's because the Zend_Navigation object is not in the view.

I would look at migrating the bootstrap to the current method, but at present I am running out of time for a release.

Thanks,

Grant

+1  A: 

First you need to work out whether your suspicion that Zend_Navigation is not in the view is correct. Easiest way to do this would be to add:

var_dump($this->view->navigation());exit;

to your controller init(). This should return the Zend_Navigation object if it's there.

If it's not there, an alternative way of supplying the Zend_Navigation object is to use the registry, which might be easier. To do this you'd remove the view stuff from your bootstrap and just do this:

$configNav = new Zend_Config_Xml('../application/config/navigation.xml', 'navigation');
$navigation = new Zend_Navigation($configNav);
Zend_Registry::set('Zend_Navigation', $navigation);

your controller init() stuff would remain the same as the view object will look in the registry if it doesn't already have a Zend Navigation object.

However, I'm not sure that your controller init() code will quite work the way that you want. I don't think findByUri() will work on Mvc pages (but I could be wrong), and from your previous question it looked like most of the pages in your XML file are Mvc ones. The Mvc class has an 'href' property which appears to be the equivalent. If your XML file contains both page types, you might need to check both, so I'd suggest something like this:

$uri = $this->_request->getPathInfo();
if (($activeNav = $this->view->navigation()->findByHref($uri)) !== null) {
    $activeNav->active = true;
} else if (($activeNav = $this->view->navigation()->findByUri($uri)) !== null) {
    $activeNav->active = true;
}
Tim Fountain
@Tim Fountain, Sir you are a star!!! Twice in one day THANKS! I tell you if it wasn't for this site and a bucket load of coffee I am sure I would be having a nervous breakdown by now!! again many thanks!
Grant Collins