如何显示zf2错误?

时间:2012-11-02 10:36:41

标签: error-handling nginx zend-framework2

我已经重新安装了我的系统,现在当zf2出现问题我只能在nginx错误日志中看到页面上的错误时,display_errors On和display_startup_errors On,在php.ini中,也许是我的php-fpm设置? 在简单的php文件中,不在zf2中,我看到了错误!

6 个答案:

答案 0 :(得分:12)

您需要在配置中启用以下选项

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
)

请记住在生产环境中关闭它

答案 1 :(得分:11)

我的index.php中的

ini_set('display_errors', true);现在显示错误

答案 2 :(得分:3)

Zend框架2将合并来自所有已加载模块的配置,因此您需要确保已在所有中将'display_exceptions'(如果该密钥存在)设置为true模块的配置文件。

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
)

您可以在application.config.php文件中看到加载了哪些模块

答案 3 :(得分:3)

您可以将上述内容与环境检查结合起来:

将此添加到顶部的public / index.php:

$env = getenv('APP_ENV') ?: 'production';
if($env == "development") {
  error_reporting(E_ALL | E_STRICT);
  ini_set('display_errors', true);
}

这一个给你的公众/ .htaccess:

SetEnv "APP_ENV" "development"

答案 4 :(得分:2)

将此添加到您的public / index.php

error_reporting(E_ALL | E_STRICT);

答案 5 :(得分:0)

在我的情况下,Zend错误和NGinX - php5 fpm,工作方式如下:

只有我输入public/index.php(@ AlloVince)

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

没有If(){...}

但是如果只是把上面的代码,显示错误,将给出这个:

Parse error: syntax error, unexpected '}', expecting ',' or ';' in /usr/local/nginx/html/ZendSkeletonApplication/module/Album/src/Album/Controller/AlbumController.php on line 12

另一件事!设置此代码:(@ To Nong)

'display_not_found_reason' => true,
'display_exceptions'       => true,
module.config.php这样的

'view_manager' => array(
 'template_path_stack' => array(
     'album' => __DIR__ . '/../view',
     'display_not_found_reason' => true,
     'display_exceptions'       => true,
 ),

),

我在屏幕上收到错误日志的所有错误:

Fatal error: Uncaught exception 'Zend\View\Exception\InvalidArgumentException' with message 'Invalid path provided; must be a string, received boolean' in /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/View/Resolver/TemplatePathStack.php:201 Stack trace: #0 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/View/Resolver/TemplatePathStack.php(149): Zend\View\Resolver\TemplatePathStack->addPath(true) #1 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/Mvc/Service/ViewTemplatePathStackFactory.php(38): Zend\View\Resolver\TemplatePathStack->addPaths(Array) #2 [internal function]: Zend\Mvc\Service\ViewTemplatePathStackFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'viewtemplatepat...', 'ViewTemplatePat...') #3 /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(939): call_user_func(Array, Object(Zend in /usr/local/nginx/html/ZendSkeletonApplication/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 946

我没有在系统(Ubuntu 14.04)中将配置文件作为php-fpm触摸。