Zend framework2 ZF2-Zend framework 2,显示登录模板
在ZF2中,我们可以在应用程序控制器中设置模板:Zend framework2 ZF2-Zend framework 2,显示登录模板,zend-framework2,Zend Framework2,在ZF2中,我们可以在应用程序控制器中设置模板: 'layout/layout' => __DIR__ . '/../theme/metronic/view/layout/layout.phtml', 'application/index/index' => __DIR__ . '/../theme/metronic/view/application/index/index.phtml', 'error/404'
'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',
这在代码一致性方面非常有用
我的特定模板是一个管理主题,登录页面与常规布局页面完全不同。显然,我不希望管理员端菜单出现在登录页面
常规页面如下所示:
登录页面如下所示:
我已经编写了我的登录模块,但是我不知道如何覆盖总体布局/布局页面
我仍然在学习ZF2路由,我想我需要做的就是输入登录模板的正确路由。。。另一种方法是在layout/layout template.phtml文件中放入一些代码,以检查登录url是否已被访问,并提供替代模板。考虑到ZF2附带的高级路由,这似乎有点混乱
我在这里遗漏了什么吗?我找到了答案,安装起来相对简单,尽管文档并不简单 多谢: 基本步骤如下:
'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',
),
我想我会对我以前的答案进行更新。对于一个简单的应用程序,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');
如果您试图在composer控制下更改.vendor controller操作的模板,则这不是解决方案