在ZF2中,我们可以在应用程序控制器中设置模板:
'layout/layout' => __DIR__ . '/../theme/metronic/view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../theme/metronic/view/application/index/index.phtml',
'error/404' => __DIR__ . '/../theme/metronic/view/error/404.phtml',
'error/index' => __DIR__ . '/../theme/metronic/view/error/index.phtml',
这在代码一致性方面非常有用。
我的特定模板是管理主题,登录页面与常规布局页面完全不同。显然我不希望管理员侧菜单出现在登录页面中......
一般页面如下所示:http://www.keenthemes.com/preview/index.php?theme=metronic_admin&page=index.html
登录页面如下所示:http://www.keenthemes.com/preview/index.php?theme=metronic_admin&page=index.html
我已经编写了我的登录模块,但我不知道如何覆盖常规布局/布局页面。
我仍然要掌握ZF2路由,我认为我需要做的就是输入正确的路由到登录模板...另一种方法是将一些代码放在layout / layout template.phtml文件中检查是否已访问登录URL并提供备用模板。考虑到ZF2附带的高级路由,这看起来有点混乱。
我在这里错过了什么吗?
答案 0 :(得分:0)
我找到了答案并且安装相对简单,尽管文档并不简单。
感谢您:http://www.webtrafficexchange.com/zf2-configure-layout-each-module-edpmodulelayouts
基本步骤如下:
在application.config.php中启用:
'模块' =>阵列( '应用&#39 ;, ' EdpModuleLayouts' ),
在application / module.config.php文件中,添加布局。这是我的:
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'login/layout' => __DIR__ . '/../view/login/login.phtml',
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
//Use this to set a custom layout
'module_layouts' => array(
'Login' => 'login/layout',
),
答案 1 :(得分:0)
我以为我会在之前的回答中添加更新。对于一个简单的应用程序,EdpModuleLayouts是完美的,但是甚至有一种更简单的方法来更改我在上一个答案之后发现的模板。
在您选择的应用程序模块或模块中按照惯例创建模板映射:
'template_map' => array(
'login/layout' => __DIR__ . '/../view/login/login.phtml',
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
然后在控制器的操作中,只需使用:
$this->layout('login/layout');
如果您尝试在编辑器控件下更改.vendor控制器操作的模板,则这不是解决方案。