【发布时间】:2014-04-06 00:49:55
【问题描述】:
我从一个配置的模块 Common 开始:
<?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',
),
),
);
该模块包含: zf2-client\module\Common\view\layout\layout.phtml
当我访问路线时,我会看到一个页面并加载布局。我有另一个模块 Wall 并且已配置:
<?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',
),
),
);
当我访问路由'/:username'时,我注意到Common 模块中描述的布局正在自动加载。 Wall 模块如何知道从 common 加载布局? Wall 模块在其视图文件夹中不包含布局,但似乎是从 Common 加载的。如果 Zend 的网站上有任何文档描述了布局系统的此功能,我还无法挖掘出来。 Wall 或 Common 的控制器中没有任何内容表明正在设置模板。所以任何地方的控制器代码中都没有 setTemplate。
感谢您发布...
【问题讨论】: