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.
Model:
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'");
}
....
}
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.