afterFind is a void method and shouldn't return anything.
Also, try something simpler to narrow down where the error is taking place.
// Not tested
public function afterFind()
{
$this->create_time = date('F, j, Y', strtotime($this->create_time));
parent::afterFind();
}
I do something similar to convert UTC time to my user's local time. I've implemented it as a behavior but you could do the same in the model.
// Model
public function behaviors()
{
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'created',
'updateAttribute' => null,
),
'TimezoneBehavior' => array(
'class' => 'application.components.behaviors.BNDTimezoneBehavior',
'attributes' => array(
'created'
)
),
);
}
<?php
/**
* BNDTimezoneBehavior class file.
*
* @author Matt Skelton
* @date 25-Aug-2012
*/
/**
* Coverts database datetime fields (stored as UTC) to the user's local timezone.
*/
class BNDTimezoneBehavior extends CActiveRecordBehavior
{
public $attributes = array();
/**
* Converts the database's stored DateTime field into the user's local time.
* @param CEvent $event
*/
public function afterFind($event)
{
if (Yii::app() instanceof CWebApplication)
{
if (Yii::app()->user->getState('timezone'))
{
$timezone = Yii::app()->user->timezone;
foreach ($this->attributes as $attribute)
{
$date = $this->getOwner()->{$attribute};
$serverTimezone = new DateTimeZone("UTC");
$localTimezone = $timezone;
$date = new DateTime($date, $serverTimezone);
$date->setTimezone(new DateTimeZone($localTimezone));
$this->getOwner()->{$attribute} = $date->format('Y-m-d H:i:s');
}
}
}
}
/**
* Converts the user's local time back into UTC.
* @param CEvent $event
*/
public function beforeSave($event)
{
if (Yii::app() instanceof CWebApplication)
{
if (!$this->owner->isNewRecord)
{
if (Yii::app()->user->getState('timezone'))
{
$timezone = Yii::app()->user->timezone;
foreach ($this->attributes as $attribute)
{
$date = $this->getOwner()->{$attribute};
$serverTimezone = new DateTimeZone("UTC");
$date = new DateTime($date, new DateTimeZone($timezone));
$date->setTimezone($serverTimezone);
$this->getOwner()->{$attribute} = $date->format('Y-m-d H:i:s');
}
}
}
}
}
}
?>
Matt