SnIpY
(Snipyowns)
April 9, 2012, 8:13am
1
I followed this tutorial: http://www.yiiframework.com/wiki/197/local-time-zones-and-locales/ and did the exact same thing. For some reason I get the following error when the beforeSave is triggered:
Fatal error: Call to a member function format() on a non-object in /home/devel-snipy/protected/components/LocalTime.php on line 209
Any clues?
abennouna
(Abennouna)
April 9, 2012, 8:56am
2
If you read the comments in the wiki, you’ll find these comments from herculesmorse:
#4312: herculesmorse at 2011/06/24 03:56pm
getting the following erorr
Call to a member function format() on a non-object in /../protected/components/LocalTime.php on line 209
#4313: herculesmorse at 2011/06/24 04:09pm
just worked out…
Wasn’t using it inside afterSave. what function can I use to convert the date outside of aftersave?
#4314: herculesmorse at 2011/06/24 05:04pm
Found the problem
Was getting it on Aftersave as well.
Have found the reason why -
http://stackoverflow.com/questions/2943591/whats-wrong-with-datetime-object
To sum up, the problem seems to lay within the use of setTimezone method. In PHP 5.2, that method returns NULL on success. Starting from PHP 5.3, the method returns the DateTime object on success.
I guess you’re using PHP 5.2, in that case you could (should) change line 206 from
$servertime = $servertime->setTimeZone($this->serverDateTimeZone);
into
$servertime->setTimeZone($this->serverDateTimeZone);