Take the 2-minute tour ×

the directory structure I'm trying to achieve would be this:

public/index.php (bootstrap)

but I can't figure out how to let Zend find my layout.phtml in each of my modules.

in my bootstrap I have:

define('APPLICATION_ENVIRONMENT', 'testing');

//setup path to our library files
                  get_include_path() );

//register the autoloader
require_once 'Zend/Loader.php';

//set config in the registry
$config = new Zend_Config_Ini( APPLICATION_PATH . '/../config/config.ini', APPLICATION_ENVIRONMENT ); 

//setup logging
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../log/debug.log');
$logger = new Zend_Log($writer);

$frontController = Zend_Controller_Front::getInstance();
//initialize Zend_Layout's MVC helpers


try {


} catch (Exception $exception) {

    echo '<html><body><center>'  . 'An exception occured while dispatching the front controller.'; 
    if (defined('APPLICATION_ENVIRONMENT') && APPLICATION_ENVIRONMENT != 'production'  ) {
        echo '<br /><br />' . $exception->getMessage() . '<br />'  . '<div align="left">Stack Trace:' . '<pre>' . $exception->getTraceAsString() . '</pre></div>'; 
    echo '</center></body></html>';

Where am I going wrong?


I haven't looked at this in a long time, so the accepted solution may not be up-to-date. If anyone wants to post a more up-to-date solution to this question (i.e. ZF 1.8+), please do so! It would be helpful to others who are looking for a solution to this.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

You should check out Per Module Zend_Layout, in this article, the author covers exactly what you are trying to achieve. His methodology is to write a plugin for the front controller that handles layout registration.

share|improve this answer
add comment

Using Zend Framework 1.12 (Haven't tested it on previous versions): works out of the box!

I usually use application.ini to setup things so, in orther to enable layouts:

resources.layout.layout = "layout"

...or whatever the default layout should be called. As "layoutPath" has not been defined Zend_Layout will look into "Application/modules//views/scripts" for a file called "layout.phtml"

If you use zend tool it will start layouts with the following line:

resources.layout.layoutPath = APPLICATION_PATH "layouts/scripts"

This is also fine, just delete the directory or avoid creating the default "layout.phtml". If the default layout is not found in that directory it will look into de modules as before for the "layout.phtml" inside "Application/modules//views/scripts".

If the layout is not found inside a module it will load the layout of the default module.

As simple as that!

If you need some extra work with your template you can add a plugin to it for example:

resources.layout.pluginClass = "YourLibrary_Controller_Plugin_Layout"

and do some extra stuff inside it.

share|improve this answer
add comment

Your Answer


