如何在Zend Framework 2中打开PHP错误报告? [英] How do I turn on the PHP error reporting in Zend Framework 2?

查看:115
本文介绍了如何在Zend Framework 2中打开PHP错误报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我在Zend Framework 2中收到错误时,我只会显示500 Internal Server Error,并且必须在Zend Server错误日志中进行搜索. 我尝试将其放入我的config/autoload/local.php文件中,但是它不起作用:

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. I've tried putting this to my config/autoload/local.php file but it doesn't work:

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

推荐答案

zf2(afaik)没有对此的本地支持.您要么必须在php.ini本身中设置它们,要么在index.php中设置它们

There is no native support for that in zf2 (afaik). You'd either have to set them in php.ini itself, or set them in index.php

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

如果您真的希望能够将它们作为配置设置提供,则可以保留现有内容,并在模块引导程序中执行此操作,从config中获取它们,然后在每个键值对上调用ini_set()

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

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);
        }
    }
}

正如@a​​kond在注释中正确指出的那样,您可以将ini_set行添加到local.php中,这是一个更好的解决方案.

as @akond rightly points out in the comments, you could just add the ini_set lines to local.php which is a better solution.

这篇关于如何在Zend Framework 2中打开PHP错误报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆