Php CGridView-YII框架中的日期格式问题
我试图在CGridView中显示创建的日期列,在DB中,它的数据类型是DateTime。 我已使用以下代码设置日期格式Php CGridView-YII框架中的日期格式问题,php,yii,cgridview,Php,Yii,Cgridview,我试图在CGridView中显示创建的日期列,在DB中,它的数据类型是DateTime。 我已使用以下代码设置日期格式 array( 'name'=>'created', 'header'=>'created', 'value' => 'Yii::app()->dateFormatter->format("d/M/y",strtotime($data->created))'
array( 'name'=>'created',
'header'=>'created',
'value' => 'Yii::app()->dateFormatter->format("d/M/y",strtotime($data->created))'
),
我在CGridView中获得了日期格式化列,但null值在列中显示sysdate。请参阅附件中的图片
请提供任何删除空值列中sysdate的解决方案
使用CGridView的属性并设置:
'nullDisplay'=>''
嗯,strotime(null)
将返回false
(Kami显然是错的)
问题出现在Yii日期格式化程序中:Yii::app()->dateFormatter->format(“d/M/y”,false)
将返回当前日期
您只需在模型中创建一个getter:
function getCreatedDate()
{
if ($this->created===null)
return;
return Yii::app()->dateFormatter->format("d/M/y", $this->created);
}
在栅格视图列中,您只需使用:
array('name'=>'created','value'=>'$data->createdDate')
- 或
'createdDate'