1

ZF3 を使用していますが、エラー ページのレイアウトを変更する必要があります。これらは、アプリケーションmodules.configファイルの次の構成によって呼び出されます。

   'view_manager' => [
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => [
            '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' => [
            __DIR__ . '/../view',
        ],
    ],

404.phtmlindex.phtmlページの特定のレイアウトを設定するにはどうすればよいですか?

4

1 に答える 1

3

特定のアクションに特定のレイアウトが必要な場合は、コントローラーで使用できます。

$this->layout()->setTemplate('layout/anOtherLayout');

コントローラーのすべてのアクションを同じレイアウトにしたい場合、コントローラーはそのメソッドを継承AbstractActionControllerしてオーバーライドできます。onDispatch()

class IndexController extends AbstractActionController 
{
    public function onDispatch(MvcEvent $e) 
    {
        // Call the base class onDispatch() first and grab the response
        $response = parent::onDispatch($e);        

        $this->layout()->setTemplate('layout/layout2');                
        // Return the response
        return $response;
    }
}

Module.phpルートが存在するかどうかを確認し (404)、存在しない場合は特定のレイアウトを設定できる場所で、同じロジックを使用できます。

于 2016-12-09T20:15:39.760 に答える