如何在列表页面格式化日期 [英] How to format date in listing page

查看:153
本文介绍了如何在列表页面格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Yii框架的新手,刚刚开始在现有的网站上工作。我有一个列表页面,我的要求是添加一个新的字段'review_date_time',我可以设法在列表中显示它。现在我的问题是如何更改日期的格式以及如果日期不在表字段中显示空格。如果没有日期,则显示0000-00-00 00:00:00。 / p>

我的代码列表

  $ this-> widget(' zii.widgets.grid.CGridView',array(
'id'=>'series-grid',
'dataProvider'=> $ model-> search(),
'filter'=> $ model,
'columns'=> array(
array('header'=>'Category','name'=>'category.title'
'exam_year',
'title',
'review_date_time',
数组(
'class'=>'CButtonColumn',

),
));


解决方案

如果显示 0000-00- 00 00:00:00 那么这意味着该值是db表中的默认值,因此您必须使用 value 属性 CDataColumn:

  $ this-> widget('zii.widgets。 grid.CGridView',array(
'id'=>'series-grid',
'dataProvider'=> $ model-> search(),
'filter'= > $ model,
//'nullDisplay'=>'',
'columns'=> array(
array('header'=>'Category','name '=>'category.title'),
'exam_year',
'title',
//'review_date_time',
array(
'name' =>' '$ $ $ $'$'$'$'$'$'$'$'$'$'$'
数组(
'class'=> 'CButtonColumn',
),
),
));

或尝试 nullDisplay 属性(如果要存储null并覆盖afterFind以将null格式化为0000-00-00 00:00:00):



<$ ('zii.widgets.grid.CGridView',数组(
'id'=>'系列网格',
' dataProvider'=> $ model-> search(),
'filter'=> $ model,
'nullDisplay'=>'',
'columns'=> array(
array('header'=>'Category','name'=>'category.title'),
'exam_year',
'title',
'review_date_time',
数组(
'class'=>'CButtonColumn',
),
),
));


I am new to Yii framework and just started to work on an existing website. I have a listing page and my requirement was to add a new field 'review_date_time' and I could managed to display it in listing. Now my question is how to change the format of the date and how to show a white space if date is not there in table field.Right now it is displaying 0000-00-00 00:00:00 if no date is there.

My code for listing

 $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'series-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
                    array('header' => 'Category', 'name' => 'category.title'),
                    'exam_year',
                    'title',
                    'review_date_time',
                    array(
                        'class' => 'CButtonColumn',
                    ),
    ),
 ));

解决方案

If it is showing 0000-00-00 00:00:00 then it means that, that value is the default value in the db table, hence you'll have to use the value property of CDataColumn:

$this->widget('zii.widgets.grid.CGridView', array(
 'id' => 'series-grid',
 'dataProvider' => $model->search(),
 'filter' => $model,
 // 'nullDisplay'=>'',
 'columns' => array(
                array('header' => 'Category', 'name' => 'category.title'),
                'exam_year',
                'title',
                // 'review_date_time',
                array(
                    'name'=>'review_date_time',
                    'value'=>'$data->review_date_time=="0000-00-00 00:00:00"?"":$data->review_date_time'
                )
                array(
                    'class' => 'CButtonColumn',
                ),
 ),
));

Or try the nullDisplay property of CGridView (if you are storing null and overriding afterFind to format null as 0000-00-00 00:00:00):

$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'series-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'nullDisplay'=>'',
'columns' => array(
                array('header' => 'Category', 'name' => 'category.title'),
                'exam_year',
                'title',
                'review_date_time',
                array(
                    'class' => 'CButtonColumn',
                ),
 ),
));

这篇关于如何在列表页面格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆