gpt4 book ai didi

php - ZendFramework 2 : Set date_default_timezone

转载 作者:行者123 更新时间:2023-12-04 16:20:54 26 4
gpt4 key购买 nike

我是 Zend Framework 2 的新手,想知道是否有一种全局方式来设置日期默认时区。

我知道我应该能够添加代码:

date_default_timezone_set("UTC");

但是我已经找了大约一个小时,找不到解决这个问题的答案。

我也尝试过在 php.ini 中设置它,但我不确定这是否会抑制错误消息。

提前致谢。

最佳答案

我的“优雅方式”是使用 onBootstrap 从配置文件中覆盖 php 设置。在我的 global.php 中,我添加了我需要为应用程序设置的 php 设置:

return array(
'php_settings' => array(
'date.timezone' => 'UTC',
'memory_limit' => '128M',
'display_errors' =>'On'
)
);

然后,onBootstrap:

    //Enable php settings from config file into the web app
$services = $e->getApplication()->getServiceManager();
$config = $services->get('config');
$phpSettings = $config['php_settings'];
if ($phpSettings) {
foreach ($phpSettings as $key => $value) {
ini_set($key, $value);
}
}

关于php - ZendFramework 2 : Set date_default_timezone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com