Timezone and more problems with Cakephp 1.3 and PH

2019-04-19 01:12发布

on server i have php 5.3.2, and cakephp 1.3.

when i run cakephp application, it gives me following errors:

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]

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

Timezone in php.ini is defined as Europe/London

I'm always getting that error, despite I define or not date_default_timezone_set('UTC'), or Europe/London, or whatever...

really frustrating......... please help...

UPDATE: something is wrong with my installation of php... if i run

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

... it gives me blank screen. no result...

is there maybe a problem?

5条回答
做个烂人
2楼-- · 2019-04-19 01:18

To handle the first warning you need to uncomment the line date_default_timezone_set('UTC'); in /app/config/core.php. You can replace UTC with your timezone as Leo suggested.

查看更多
趁早两清
3楼-- · 2019-04-19 01:24

As Leo Said, is an issue with PHP 5.3. The best solution is to modify your web server php.ini and set

[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:

php_flag date.timezone = "Europe/Rome"
查看更多
迷人小祖宗
4楼-- · 2019-04-19 01:25

I had this error for a while since the hosting co. upgraded to 5.3 too

In the /app/config/config.php, around line 244, there's a note about un-commenting the next line when running on 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

查看更多
狗以群分
5楼-- · 2019-04-19 01:27

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

You probably want to replace America/Anchorage with your timezone.

查看更多
时光不老,我们不散
6楼-- · 2019-04-19 01:40

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:

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

    //run controllers and actions that cause error here

}

Adding 'Core' to App::import() solved it for me.

查看更多
登录 后发表回答