2015-08-14 120 views
4

我试图建立一个symfony的2.7基于应用一个共享服务器上有无权改变的php.ini致命错误。Symfony的2.7:默认时区没有设置,导致

执行:php app/console doctrine:schema:drop --force

输出这个警告/错误:

PHP Warning: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' 
0 [internal function]: Symfony\Component\Debug\ErrorHandler- >handleError(2, 'date_default_ti...', '/path...', 272, Array) 
1 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php(272): date_default_timezone_get() 
2 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php(481): Monolog\Logger->addRecord(100, 'Notified event ...', Array) 
3 /domain.com/app/vendor/symfony/ in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272 
PHP Fatal error: date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272 
PHP Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272 
PHP Fatal error: date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /domain.com 

我试图this

class AppKernel extends Kernel 
{ 
    public function init() 
    { 
     date_default_timezone_set('Europe/Berlin'); 
     parent::init(); 
    } 
} 

输出下一个错误:

PHP Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Notice: date_default_timezone_set(): Timezone ID 'Europe/Berlin' is invalid' in /domain.com/app/app/AppKernel.php:42 

根据php.netEurope/Berlin是一个有效的标识符。按照this answertimezonedb.so应该安装(不是)。

根据Symfony 1.4 docs可以在settings.yml中设置default_timezone。我无法找到>= 2.0的类似配置。 编辑“不同于Symfony的1.4,没有一个default_timezone配置参数来设置Symfony2的默认时区[...]。”source

任何想法,如何解决这个问题呢?

在此先感谢!

+0

由于缺省的时区尚未在php.ini文件中设置,因此会出现此错误消息。请看看这个答案。 http://stackoverflow.com/questions/24251793/warning-date-default-timezone-get-installing-symfony – Praveesh

+0

@Praveesh如上所述,我已经试过这个解决方案,我很遗憾仍然不允许编辑PHP的.ini。 –

+1

只需更换您的主机。 –

回答

14

,建议您设置的时区在php.ini,但如果你是在共享环境中,或者如果你没有访问它由于某种原因,你可以在app/AppKernel.php

class AppKernel extends Kernel 
{ 
     public function __construct($environment, $debug) 
     { 
      date_default_timezone_set('America/Detroit'); 
      parent::__construct($environment, $debug); 
     } 
} 
+0

或者将相同的行添加到web/app.php – Cerad

1

添加此在少给我@wonde答案没有工作,我不知道为什么,这个工作对我来说

ini_set('date.timezone', 'Europe/Berlin'); 

添加此行的文件:

/web/app_dev.php

/web/app.php

,如果这不工作在内核中添加过多。

这解决了我的问题!