我有两个模块:
->Patient
->Doctor
project/
指向Patient
模块,project/doctor
指向Doctor
模块。
因此,当我输入project/forgotpass
时,它应指向Patient
模块中的404错误页面,但它指向Doctor
404错误页面。
如何设法指向相应的404错误页面。
在Patient
模块配置中:
'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(
'layout/patient' => __DIR__ . '/../view/layout/layout.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
)
)
在Doctor
模块配置中:
'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(
'layout/doctor' => __DIR__ . '/../view/layout/layout.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
)
)
是否可以拥有单独的404页面,或者我应该调用相应的模块404错误页面。我的问题是Patient
模块正在调用Doctor
404错误页面。
答案 0 :(得分:0)
将模板名称更改为不同的名称:
'not_found_template' => 'error/patient/404',
'exception_template' => 'error/patient/index',
并在模板地图中使用它们:
'error/patient/404' => __DIR__ . '/../view/error/404.phtml',
'error/patient/index' => __DIR__ . '/../view/error/index.phtml',
答案 1 :(得分:0)
来自不同模块的配置数组在引导程序中全部合并到一个应用程序范围的配置数组中。这意味着具有相同名称的键将被最后加载的文件覆盖。
您可以通过执行以下操作来查看合并的配置结果:
$config = $serviceManager->get('Config');
layout/doctor
和layout/patient
是唯一名称,因此不会被覆盖。但是密钥error/404
并不是唯一的,因此它将被覆盖。
您可能会在Doctor
模块之后加载Patient
模块,以便显示医生模块中的error/404
。
如果按相反的顺序加载,它会显示患者模块中的error/404
(试试:) :)。
因此,所有这些合并的配置意味着您只能在not_found_template
密钥下定义exception_template
和view_manager
一次:
'view_manager' => array(
'not_found_template' => 'error/404',
'exception_template' => 'error/index'
)
错误页面通常在Application
模块中定义一次,并用于整个ZF2应用程序中的所有模块。