繁体   English   中英

处理zf2模块中的404错误页面

[英]handing the 404 error page in zf2 modules

我有两个模块:

->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错误页面。

将模板的名称更改为其他名称:

'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',

来自不同模块的配置数组位于引导程序上,所有这些合并到一个应用程序范围的配置数组中。 这意味着具有相同名称的密钥将被最后一个加载的文件覆盖。

您可以通过执行以下操作查看合并的配置结果:

$config = $serviceManager->get('Config');

layout/doctorlayout/patient是唯一的名称,因此不会被覆盖。 但是关键error/404不是唯一的,因此它将被覆盖。

您可能在“ Patient Doctor模块之后加载“ Doctor模块,因此将显示“医生”模块的error/404

如果以相反的顺序加载,它将在您的Patient模块中显示error/404 (尝试:))。


因此,所有这些配置合并意味着您只能在view_manager项下定义一次not_found_templateexception_template

'view_manager' => array(
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index'
)

错误页面通常在Application模块中定义一次,并用于整个ZF2应用程序中的所有模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM