Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend 2为控制器定义错误页_Php_Zend Framework_Error Handling_Zend View_Zend Controller - Fatal编程技术网

Php Zend 2为控制器定义错误页

Php Zend 2为控制器定义错误页,php,zend-framework,error-handling,zend-view,zend-controller,Php,Zend Framework,Error Handling,Zend View,Zend Controller,我有一个带有几个控制器的模块。我想对除一个控制器之外的所有控制器使用正常错误页面 是否可以定义一个仅在某个控制器中引发异常时使用的错误页 这就是模块配置的外观: 'view_manager' => array( 'display_not_found_reason' => true, 'display_exceptions' => true, 'doctype' => 'HTML5', 'not_

我有一个带有几个控制器的模块。我想对除一个控制器之外的所有控制器使用正常错误页面

是否可以定义一个仅在某个控制器中引发异常时使用的错误页

这就是模块配置的外观:

'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/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'layout/header'           => __DIR__ . '/../view/layout/header.phtml',
        'layout/footer'           => __DIR__ . '/../view/layout/footer.phtml',
        'layout/sidebar'          => __DIR__ . '/../view/layout/sidebar.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'pagination/sliding'      => __DIR__ . '/../view/pagination/sliding.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ),
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),

我知道我可以通过将此控制器放入一个额外的模块并为此模块定义一个错误页面来实现类似的效果,但我不想将我的项目拆分为多个模块。

找到了解决问题的方法:

在模板映射中定义错误模板:

    'template_map' => array(
          ...
          'error/controller'      => __DIR__ . '/../view/error/controller/index.phtml',
    ),
在控制器构造方法中设置模板:

public function __construct()
{  
      $this->getServiceLocator()->get('ViewManager')->getExceptionStrategy()->setExceptionTemplate('error/controller');
}