时区和 Cakephp 1.3 和 PHP 5.3.2 的更多问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3370403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Timezone and more problems with Cakephp 1.3 and PHP 5.3.2
提问by user198003
on server i have php 5.3.2, and cakephp 1.3.
在服务器上,我有 php 5.3.2 和 cakephp 1.3。
when i run cakephp application, it gives me following errors:
当我运行 cakephp 应用程序时,它给了我以下错误:
Warning (2): strtotime() [http://php.net/function.strtotime]: It is not safe to rely on the system's timezone settings. You are requiredto 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 'Europe/Berlin' for 'CEST/2.0/DST' instead [ROOT/cakephp/cake/libs/cache.php, line 570]
警告 (2):strtotime() [ http://php.net/function.strtotime]:依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们为“CEST/2.0/DST”选择了“欧洲/柏林”,而不是 [ROOT/cakephp/cake/libs/cache.php, line 570]
Also, I'm getting some more errros:
另外,我得到了更多的错误:
Notice: Trying to get property of non-object in /htdocs/cakephp/cake/libs/cache/file.php on line 248 Fatal error: Call to a member function cd() on a non-object in /htdocs/cakephp/cake/libs/cache/file.php on line 248
注意:尝试在第 248 行的 /htdocs/cakephp/cake/libs/cache/file.php 中获取非对象的属性致命错误:在 /htdocs/cakephp/ 中的非对象上调用成员函数 cd() cake/libs/cache/file.php 在第 248 行
Timezone in php.ini is defined as Europe/London
php.ini 中的时区定义为 Europe/London
I'm always getting that error, despite I define or not date_default_timezone_set('UTC'), or Europe/London, or whatever...
我总是遇到那个错误,不管我是否定义了date_default_timezone_set('UTC'),或者欧洲/伦敦,或者其他什么......
really frustrating......... please help...
真的很郁闷……请帮忙……
UPDATE: something is wrong with my installation of php... if i run
更新:我的 php 安装有问题...如果我运行
<?php echo date('Y'); ?>
... it gives me blank screen. no result...
...它给了我空白屏幕。没有结果...
is there maybe a problem?
可能有问题吗?
回答by bancer
To handle the first warning you need to uncomment the line date_default_timezone_set('UTC');in /app/config/core.php. You can replace UTCwith your timezone as Leo suggested.
要处理第一个警告,您需要取消注释date_default_timezone_set('UTC');/app/config/core.php 中的行。您可以UTC按照 Leo 的建议替换为您的时区。
回答by Valentino Dell'Aica
As Leo Said, is an issue with PHP 5.3. The best solution is to modify your web server php.ini and set
正如 Leo 所说,这是 PHP 5.3 的一个问题。最好的解决办法是修改你的web服务器php.ini并设置
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Rome"
Or if you can't modify web server php.ini you can add this options to root .htaccess file on your site:
或者,如果您无法修改 Web 服务器 php.ini,则可以将此选项添加到您站点上的根 .htaccess 文件中:
php_flag date.timezone = "Europe/Rome"
回答by Adam Prax
I had the exact same problem and Googling led me to this post.
我遇到了完全相同的问题,谷歌搜索让我找到了这篇文章。
I fixed the problem by adding the line date_default_timezone_set("America/Anchorage");to the top of [cake base directory]/libs/cache.php
我通过将这一行添加date_default_timezone_set("America/Anchorage");到[cake base directory]/libs/cache.php的顶部来解决这个问题
You probably want to replace America/Anchoragewith your timezone.
您可能想用您的时区替换America/Anchorage。
回答by Zoltan H
I had this error for a while since the hosting co. upgraded to 5.3 too
自从托管公司以来,我遇到了这个错误一段时间。也升级到 5.3
In the /app/config/config.php, around line 244, there's a note about un-commenting the next line when running on 5.3
在 /app/config/config.php 中,第 244 行左右,有一条关于在 5.3 上运行时取消注释下一行的注释
I just changed the next line to:
我只是将下一行更改为:
date_default_timezone_set('America/Toronto'); // your favourite time-zone here - and don't get me started about why Toronto is U.S. city (joking)
You could put that line in bootstrap.php, but you might get this error still, config.php is loaded first
您可以将该行放在 bootstrap.php 中,但您可能仍然会收到此错误,首先加载 config.php
回答by Bryan Plasters
I ran into this when using cakeshell to run command line cron scripts. After much hassle I figured out that in addition to bancer's solution above I needed import core.php into my php shell scripts as such:
我在使用 cakeshell 运行命令行 cron 脚本时遇到了这个问题。经过一番折腾,我发现除了上面的 bancer 解决方案外,我还需要将 core.php 导入到我的 php shell 脚本中,如下所示:
function main() {
App::import('Controller', 'Core');
//run controllers and actions that cause error here
}
Adding 'Core' to App::import() solved it for me.
将“核心”添加到 App::import() 为我解决了这个问题。

