簡體   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