[英]How do I turn on the PHP error reporting in Zend Framework 2?
每次我在Zend Framework 2中收到錯誤時,我只顯示500內部服務器錯誤,並且必須搜索Zend Server錯誤日志。 我已經嘗試將它放到我的config / autoload / local.php文件中,但它不起作用:
return array(
'phpSettings' => array(
'display_startup_errors' => true,
'display_errors' => true,
),
);
在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);
}
}
}
編輯:正如@akond在評論中正確指出的那樣,你可以將ini_set行添加到local.php
這是一個更好的解決方案。
要在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',
),
);
查看此博客文章了解更多信息!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.