Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CGridView-YII框架中的日期格式问题_Php_Yii_Cgridview - Fatal编程技术网

Php CGridView-YII框架中的日期格式问题

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))'

我试图在CGridView中显示创建的日期列,在DB中,它的数据类型是DateTime。 我已使用以下代码设置日期格式

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'