I'm starting with a module Common that is configured:
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Common\Controller\Index',
'action' => 'index',
),
),
),
),
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Common\Controller\Index' => 'Common\Controller\IndexController'
),
),
'view_helpers' => array(
'invokables' => array(
'flashMessengerHelper' => 'Common\View\Helper\FlashMessenger',
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
The module contains: zf2-client\module\Common\view\layout\layout.phtml
When I visit the route I am presented with a page and the layout is loaded. I have another module Wall and it is configured:
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'router' => array(
'routes' => array(
'wall' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/:username',
'constraints' => array(
'username' => '\w+'
),
'defaults' => array(
'controller' => 'Wall\Controller\Index',
'action' => 'index',
),
),
)
),
),
'controllers' => array(
'invokables' => array(
'Wall\Controller\Index' => 'Wall\Controller\IndexController'
),
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
When I visit the route '/:username' I notice that the layout described in the Common module is automatically being loaded. How does the Wall module know to load the layout from common? The Wall module contains no layout in its view folders but one appears to be loaded from Common. If there is any documentation on Zend's website that describes this functionality of the layout system I have not been able to dig it out yet. There is nothing in the controller of Wall or Common that indicates a template is being set. So no setTemplate is in the controller code anywhere.
Thank you for posting...