Issues

ZF-6747: Zend/Application/Resource/Navigation issue

Description

Fatal error when using Zend_Application Navigation Resource with custom view resource in bootstrap

ref: http://www.nabble.com/Zend-Framework-f15440.html possibly related http://nabble.com/Zend_Navigation-and-Zend_Applica…

reproduce:

Set up a ZF project via Quickstart zf Command Line Tool (which is great :))

Add to application.ini

resources.view[] = resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" resources.navigation.pages.indexFoo.label = "Foo" resources.navigation.pages.indexFoo.controller = "index" resources.navigation.pages.indexFoo.action = "foo" resources.navigation.pages.indexBar.label = "Bar" resources.navigation.pages.indexBar.controller = "index" resources.navigation.pages.indexBar.action = "bar"

In the view

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

Everything works great, the menu is echoed as expected.

But if you now add a custom view resource in the bootstrap the menu disappears?

e.g.

protected function _initView()
{
    // Initialize view
    $view = new Zend_View();
    $view->doctype('XHTML1_STRICT');
    $view->headTitle('My First Zend Framework Application');

    // Add it to the ViewRenderer
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view);

    // Return it, so that it can be stored by the bootstrap
    return $view;
}

if you then comment out view resource config in application.ini i.e. ;resources.view[] =

you get a fatal error:

Fatal error: Call to a member function getView() on a non-object in path\to\1.8.1\library\Zend\Application\Resource\Navigation.php on line 100

Comments

Assigning to Robin.

Assigning to Dolf, because he wrote the navigation resource (plus I'm super busy until june, and not too familiar with Zend_Application yet).

I set the priority of this issue to minor when creating it though I think it should be upgraded.

Why?

Use of the navigation resource (from configs file e.g ini) requires altering any bootstraps in your app that use a view initializer i.e. "_initView()" . And though making the changes may very well be trivial I think the upgrade of priority is justified.

FYI: The workaround for use of the navigation resource from configs is simply to rename your view inializer and retrieving the view resource for manipulation:

 
    public function _initViewNotNamedInitView()
    {
        $view = $this->bootstrap('view')->getResource('view');
        // now make your changes to the view
    }

I think the problem lies in Zend_Application_Resource_View

The navigation view helper always tries to get the view by: (row.99)

$view = $this->getBootstrap()->getPluginResource('view')->getView();

I use custom smarty view class, that gets initialized in Bootstrap.php. So the view plugin resource never knows from smarty view because it never gets (wanted) used/inited.

related issue in zend view resource: http://framework.zend.com/issues/browse/ZF-7061

regards, marco

Fixed with r17016 Merged into 1.9 branch with r17017

This issue is still present in 1.11.6 using the setup from documentation:

http://framework.zend.com/manual/en/…

By putting that into the application.ini the very same fatal error appears.

Yet I've been unable to think of a unittest that would demonstrate this 'faulty' behavior. Please provide a unittest that currently fails, and would pass after the issue has been fixed. If none can be provided I'll once again close this issue as resolved.

Thank you for helping making ZF better.