2016-12-05 72 views
1

我正在使用ZF3,我需要更改错误页面的布局。它们是由下面的配置,应用modules.config文件名为:如何更改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页面?

回答

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),并设置特定的布局如果不是。

相关问题