In this ZF2 example您可以将布局设置为每个模块配置中所需的布局,但是我想知道是否存在一种在模块之间共享和组织相同布局和导航的方法。
例如像模板一样,为项目中的每个模块加载没有重复的layout/layout.phtml
和partial/navigation
的默认CSS,脚本和布局,然后使用$this->headLink()->appendStylesheet()
和$this->headScript()->appendFile()
在我的特定视图中加载特定的CSS和脚本
最佳答案
您的示例中的template_map
可以在不同的模型中定义。 ZF2将所有配置合并到一个配置数组中,如here所述:
ModuleManager
的ConfigListener
聚合配置并在模块加载时将其合并。
因此,您可以在模块A和模块B中定义模板图,在配置中,您会发现两个模板图已合并。这意味着模板名称在应用程序中应该是唯一的,否则您将最终覆盖它们。
因此,在模块A module.config.php
中:
'view_manager' => array(
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout.phtml',
'moduleA/list_view' => __DIR__ . '/../view/list.phtml',
'moduleA/info_view' => __DIR__ . '/../view/info.phtml',
),
)
因此,在模块B
module.config.php
中:'view_manager' => array(
'template_map' => array(
'moduleB/list_view' => __DIR__ . '/../view/list.phtml',
'moduleB/info_view' => __DIR__ . '/../view/info.phtml',
),
)
最后将得到一个合并的
template_map
,其中包含所有内容:'layout/layout' => __DIR__ . '/../view/layout.phtml',
'moduleA/list_view' => __DIR__ . '/../view/list.phtml',
'moduleA/info_view' => __DIR__ . '/../view/info.phtml',
'moduleB/list_view' => __DIR__ . '/../view/list.phtml',
'moduleB/info_view' => __DIR__ . '/../view/info.phtml'
现在,您将可以在整个应用程序中访问这些视图。
关于css - 在ZF 2中的模块之间共享相同布局和导航的最佳实践,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34673481/