2010-07-30 21 views
16

服務器上我有php 5.3.2和cakephp 1.3。CakePHP 1.3和PHP 5.3.2的時區和更多問題

當我運行CakePHP程序,它給了我以下錯誤:

Warning (2): strtotime() [ http://php.net/function.strtotime] : 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 'Europe/Berlin' for 'CEST/2.0/DST' instead [ROOT/cakephp/cake/libs/cache.php, line 570]

另外,我也得到了一些更errros:在php.ini

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

時區被定義爲歐洲/倫敦

我總是得到那個錯誤,儘管我定義或不是date_default_timezone_set('UTC'),或歐洲/倫敦,或其他...

很無奈.........請幫助...

UPDATE:什麼是錯的我安裝PHP的...如果我跑

<?php echo date('Y'); ?> 

...它給我空白屏幕。沒有結果...

有沒有問題?

+0

你有沒有嘗試過在你的代碼中聲明時區?也許在你的app_controller的beforeFilter()? – 2010-07-30 10:18:58

+0

看起來像我有一些安裝PHP的問題...請看看我的問題的更新部分。 – user198003 2010-07-30 10:48:19

+0

***注意:*** php-cli的'php.ini'文件與'apache2'的'php.ini'文件不同。我建議將符號鏈接到另一個以保持同步並避免混淆! – 2014-02-15 19:47:10

回答

26

要處理第一條警告,您需要取消註釋/app/config/core.php中的date_default_timezone_set('UTC');行。按照Leo的建議,您可以用您的時區替換UTC

+0

不幸的是,我之前我發佈這個問題...我也嘗試了幾個不同的時區,每次都得到相同的錯誤。另外,請檢查我的問題的更新部分...出於某種原因,我不能執行簡單的PHP函數日期。我認爲可能有問題,我沒有啓用或安裝,或...? – user198003 2010-07-30 17:02:01

+0

將文件更改爲'<?php error_reporting(E_ALL);回聲日期(「Y」); ?>'。 – bancer 2010-07-30 18:33:21

+0

我確實設置了error_reporting(E_ALL),我得到的錯誤是: 警告:date():依靠系統的時區設置是不安全的。您*必須*使用date.timezone設置或date_default_timezone_set()函數。如果您使用這些方法中的任何一種,並且仍然收到此警告,則很可能是拼寫錯誤的時區標識符。我們在第9行的/htdocs/index.php中選擇了'Europe/Berlin'作爲'CEST/2.0/DST'。致命錯誤:date():時區數據庫已損壞 - 這應該永遠不會發生!在第9行的/htdocs/index.php中 – user198003 2010-08-01 09:15:32

4

我有完全相同的問題,谷歌搜索引導我到這篇文章。

我加入行date_default_timezone_set("America/Anchorage");[蛋糕基本目錄]頂部/libs/cache.php

你可能想你的時區,以取代美國/安克雷奇解決了這一問題。

+0

+1這個問題對我有用 – 2011-11-18 12:26:20

7

由於Leo Said是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" 

或者,如果你不能修改Web服務器的php.ini您可以添加這個選項來根網站上的.htaccess文件:

php_flag date.timezone = "Europe/Rome" 
+3

更多支持的時區在這裏:http://php.net/manual/en/timezones.php – geon 2012-01-01 16:34:47

2

我有這個錯誤一段時間以來,託管公司。升級到5.3太

在/app/config/config.php,圍繞線244,有一個關於取消評論5.3

運行時,下一行我只是改變了下一行注:

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) 

你可以把那條線在bootstrap.php中,但使用cakeshell運行命令行cron腳本時,你可能會得到這樣的錯誤是,config.php文件被加載第一

0

我碰到了這一點。經過許多麻煩,我發現除了上面的bancer解決方案之外,我需要導入核心。PHP的到我的PHP shell腳本這樣:

function main() { 
    App::import('Controller', 'Core'); 

    //run controllers and actions that cause error here 

} 

添加 '核心' 到App :: import()的解決了這個問題對我來說。