This extension is a Widget that takes two dates and displays them in a human friendly string.
Here are some example outcomes ~~~ "2012-12-25" and "2012-12-31" will show as "25 to 31 Dec 2012" "2012-12-25" and "2013-01-15" will show as "25 Dec 2012 to 15 Jan 2013" "2013-01-05" and "2013-02-10" will show as "05 Jan to 10 Feb 2013" ~~~
Requirements ¶
Yii 1.1 or above
Usage ¶
- Copy the extension to your protected/extensions folder.
- In a View file, insert as a Widget using "YYYY-mm-dd" formatted parameters for 'startDate' and 'endDate'. Set 'duration' to true to show the number of days in brackets as a suffix.
$this->widget('TimeString', array(
'startDate'=>$data->start_date, // assuming $data->start_date is "2012-12-25"
'endDate'=>$data->end_date, // assuming $data->end_date is "2012-12-31"
'duration'=>true,
));
CGridView
is it working on CGridView?..
RE: CGridView
Hi Peter,
Thank you for your question. I haven't tried this in CGridView, but I will try it and come back to you.
CGridView
Hi Peter,
I tried using the example I have written below but without luck. The page renders up to the point where the widget code is and then stops rendering any further. Did you have any further luck?
In the following example, I used
parent::widget
instead of
$this->widget
as "widget" is not a method of CGridView.
<?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'trip-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'id', array( 'name'=>'start_date', 'type'=>'raw', 'value'=>'parent::widget(\'TimeString\', array( \'startDate\'=>$data->start_date, \'endDate\'=>$data->end_date, ), true);', ), array( 'class'=>'CButtonColumn', ), ), )); ?>
CGridView
I see,
thx for your response. how about convert this extension into helper function? so, i could make a special AR function on model, and then call that function from CGridView? just idea..
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.