Symfony 2.7:未设置默认时区,导致致命错误

Mr.*_* B. 4 php timezone symfony server

我试图建立一个symfony的2.7一个基于应用程序共享服务器,并有没有权限修改php.ini中.

执行: 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
Run Code Online (Sandbox Code Playgroud)

我试过这个:

class AppKernel extends Kernel
{
    public function init()
    {
        date_default_timezone_set( 'Europe/Berlin' );
        parent::init();
    }
}
Run Code Online (Sandbox Code Playgroud)

输出下一个错误:

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
Run Code Online (Sandbox Code Playgroud)

根据php.net Europe/Berlin是一个有效的标识符.

根据这个答案 timezonedb.so应该安装(它不是).

根据Symfony 1.4文档,它可以设置default_timezonesettings.yml.我找不到类似的配置>= 2.0. 编辑:"与Symfony 1.4不同,没有default_timezone配置参数来设置Symfony2中的默认时区.[...]"(来源)

任何想法,如何解决问题?

提前致谢!

小智 15

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

class AppKernel extends Kernel
{
        public function __construct($environment, $debug)
        {
            date_default_timezone_set( 'America/Detroit' );
            parent::__construct($environment, $debug);
        }
}
Run Code Online (Sandbox Code Playgroud)