9

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

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

2 回答 2

8

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

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

如果您真的希望能够将它们作为配置设置提供,您可以保留您所拥有的并在模块引导程序中执行此操作,从配置中获取它们,然后在每个键值对上调用 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);
        }
    }
}

编辑:正如@a​​kond 在评论中正确指出的那样,您可以添加 ini_set 行,local.php这是一个更好的解决方案。

于 2013-03-10T10:34:17.657 回答
6

要在 ZF2 应用程序上轻松配置 phpSettings,您应该考虑使用DluPhpSettings

使用此模块,您可以为您拥有的每个环境配置设置:

/* 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',
    ),
);

查看此博客文章以获取更多信息!

于 2013-03-10T22:45:13.547 回答