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

夙愿已清 提交于 2019-12-05 19:38:57

问题


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

回答1:


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

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

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.




回答2:


To easilly configure phpSettings on your ZF2 app, you should consider using 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!



来源:https://stackoverflow.com/questions/15321115/how-do-i-turn-on-the-php-error-reporting-in-zend-framework-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!