Displaying Virutal Attribute In Cgridview

HI All,

I have used a from_date & to_date attribute to search my data and have placed it in the Model as safe attributes. Now i like to display the same from_date and to_date in the CGridview with other data form the model.

Shouldn’t I just be able to use ‘$data->from_date’ in my CGridView. But i dont understand why is it not working below is the code.


public $from_date;

public $to_date;

public function rules(){

array('from_date, to_date', 'safe', 'on'=>'search'),


public function search(){


if(!empty($this->to_date) && !empty($this->from_date))


            $criteria->addCondition("date($created_date)  >= '$this->from_date' and date($created_date) <= '$this->to_date'");

        }else if(!empty($this->from_date) && empty($this->to_date))


            $criteria->addCondition("date($created_date) >= '$this->from_date'");

        }else if(!empty($this->to_date) && empty($this->from_date))


            $criteria->addCondition("date($created_date) <= '$this->to_date'");





$model = new Tickets('search');

if (!empty($_GET)) {

$model->ticket_id = isset($_GET['ticket_id']) ? $_GET['ticket_id'] : '';

$model->from_date = isset($_GET['from_date']) ? $_GET['from_date'] : '';

$model->to_date = isset($_GET['to_date']) ? $_GET['to_date'] : '';




$this->render('search', array(

            'model' => $model



$this->widget('bootstrap.widgets.TbGridView', array(

'type' => 'striped bordered condensed',

'dataProvider' => $model->search(),

'columns' => array(


                        'name' => 'From date',

                        'type' => 'html',

                        'value' => '$data->from_date',




Please do let me know. Thanks.

Hello Giris.

you are setting the from date column’s type to html in Grid View so change the type to text or raw.

I dont know What are you expecting. But i did from date and to date search and add code here


if($this->datefrom!='' && $this->dateto!=''){


}else if($this->datefrom!=''){


}else if($this->dateto!=''){




Thank you for your help but adding text or raw doesnot seem to help.

Thank you for trying to help. But that is not my question here. Please do read the problem again. I want to display a custom or virtual attribute to CGridView. It has got nothing to do with the addBetweenCondition for date comparision.