简体   繁体   English

如何在Zend Framework 2中打开PHP错误报告?

[英]How do I turn on the PHP error reporting in Zend Framework 2?

Everytime I receive an error in Zend Framework 2, I get just 500 Internal Server Error displayed and have to search through the Zend Server error log. 每次我在Zend Framework 2中收到错误时,我只显示500内部服务器错误,并且必须搜索Zend Server错误日志。 I've tried putting this to my config/autoload/local.php file but it doesn't work: 我已经尝试将它放到我的config / autoload / local.php文件中,但它不起作用:

return array(
    'phpSettings' => array(
        'display_startup_errors' => true,
        'display_errors' => true,
        ),
);

There is no native support for that in zf2 (afaik). 在zf2(afaik)中没有本机支持。 You'd either have to set them in php.ini itself, or set them in index.php 你要么必须在php.ini中设置它们,要么在index.php中设置它们

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

If you really want to be able to supply them as config settings, you could keep what you have and do that in a module bootstrap, get them from config, and call ini_set() on each key value pair 如果你真的希望能够将它们作为配置设置提供,你可以保留你所拥有的并在模块引导程序中执行它,从配置中获取它们,并在每个键值对上调用ini_set()

public function onBootstrap(EventInterface $e) {
    $app = $e->getApplication();
    $sm = $app->getServiceManager();
    $config = $sm->get('Config');
    $phpSettings = isset($config['phpSettings']) ? $config['phpSettings'] : array();
    if(!empty($phpSettings)) {
        foreach($phpSettings as $key => $value) {
            ini_set($key, $value);
        }
    }
}

Edit: as @akond rightly points out in the comments, you could just add the ini_set lines to local.php which is a better solution. 编辑:正如@a​​kond在评论中正确指出的那样,你可以将ini_set行添加到local.php这是一个更好的解决方案。

To easilly configure phpSettings on your ZF2 app, you should consider using DluPhpSettings . 要在ZF2应用程序上轻松配置phpSettings,您应该考虑使用DluPhpSettings

With this module, you can configure your settings for each environment you have: 使用此模块,您可以为您拥有的每个环境配置设置:

/* Local application configuration in /config/autoload/phpsettings.local.php */
<?php
return array(
    'phpSettings'   => array(
        'display_startup_errors'        => false,
        'display_errors'                => false,
        'max_execution_time'            => 60,
        'date.timezone'                 => 'Europe/Prague',
        'mbstring.internal_encoding'    => 'UTF-8',
    ),
);

Look this blog post for more info too! 查看此博客文章了解更多信息!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM