2013-03-10 76 views
9

每当我在Zend Framework 2中收到一个错误时,我只显示500个内部服务器错误,必须搜索Zend Server错误日志。 我试图把这个给我的配置/自动加载/ local.php文件,但它不工作:如何打开Zend Framework 2中的PHP错误报告?

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

回答

8

没有为在ZF2没有原生支持(据我所知)。你要么必须将它们设置在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); 
     } 
    } 
} 

编辑:作为@akond正确的评论所指出的,你可以只中ini_set行添加到local.php哪些是更好的解决方案。

+3

不需要这么长的onBoostrap代码。他可以将error_reporting放在配置文件本身中,因为它是一个PHP文件。 – akond 2013-03-10 14:50:02

+0

@akond +1你是非常正确的,这是一个更好的选择,引导程序代码只是为了演示如何使OP工作。 – Crisp 2013-03-10 14:54:24

+0

这有帮助,谢谢:) – 2013-03-14 05:40:08

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

this blog post