Zend Framework

Resource Layout must bootstrap view

Details

Description

Snippet from my Bootstrap.php:
Inicializing navigation
[...]

protected function _initNavigation (){		
	$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->mainNavigation = $container;
	$view->navigation($container);
}

[...]

Layout:
<?php echo $this->Doctype();?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php echo $this->headMeta();?>
<?php echo $this->headTitle();?>
<?php echo $this->headLink();?>
<?php echo $this->headStyle();?>
<?php echo $this->headScript();?>
<?php
echo $this->jQuery();
?>
</head>
<body>
<?php echo $this->layout()->content;?>
</body>
</html>

Application.ini:
resources.view.encoding = "UTF-8"
resources.view.doctype = "XHTML1_STRICT"
resources.view.helperPath.Alarm_View_Helper = "Alarm/View/Helper/"
resources.view.helperPath.Bcom_JQuery_View_Helper = "Bcom/JQuery/View/Helper/"
resources.view.helperPath.Bcom_View_Helper = "Bcom/View/Helper/"
resources.view.helperPath.ZendX_JQuery_View_Helper = "ZendX/JQuery/View/Helper"

With this configuration is throwed Zend_Plugin_Loader_Exception with message: Plugin by name 'JQuery' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:./views/helpers/

So layout have not bootstrap dependenci for view => layout is bootstraped before view

Posible solution:
1. before bootstrap layour resource in bootstrap must be boostraped layout - add call bootstrap method into my Bootrap.php.
Updated _initNavigation() from my bootstrap:

protected function _initNavigation (){		
	$this->bootstrap('view'); // <<<< THIS LINE
	$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->mainNavigation = $container;
	$view->navigation($container);
}

2. add dependenci into layout bootstraping:

lestr@lestr-nb:~/projects/test/trunk/library$ svn diff Zend/Application/Resource/Layout.php
Index: Zend/Application/Resource/Layout.php
===================================================================
--- Zend/Application/Resource/Layout.php        (revision 297)
+++ Zend/Application/Resource/Layout.php        (working copy)
@@ -52,6 +52,7 @@
     public function init()
     {
         $this->getBootstrap()->bootstrap('FrontController');
+        $this->getBootstrap()->bootstrap('View');
         return $this->getLayout();
     }

lestr@lestr-nb:~/projects/test/trunk/library$

Second solution is imho very better. Layout must be bootstraped after view in all time.

Activity

Hide
Dolf Schimmel (Freeaqingme) added a comment -

I don't see how this is an issue. the layout isn't dependent on the view. Also, the Navigation resource plugin that is shipped with Zend Framework bootstraps Zend_View, but only when it is dependent on it.

Show
Dolf Schimmel (Freeaqingme) added a comment - I don't see how this is an issue. the layout isn't dependent on the view. Also, the Navigation resource plugin that is shipped with Zend Framework bootstraps Zend_View, but only when it is dependent on it.
Hide
Martin Wheatley added a comment -

This is an issue if you use a custom view helper in the layout file and zend navigation.

The above fix of inserting $this->bootstrap('view') before the layout bootstrap fixes this issue, but not without a lot of searching trying to work out why the helper wasn't available when it's defined correctly in application.ini.

Show
Martin Wheatley added a comment - This is an issue if you use a custom view helper in the layout file and zend navigation. The above fix of inserting $this->bootstrap('view') before the layout bootstrap fixes this issue, but not without a lot of searching trying to work out why the helper wasn't available when it's defined correctly in application.ini.

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: