I have in my cGridView two columns date1 and date2. I can find all my records in filters of date1 and date2. Now, I have to find my records through filters, which are older than date1 or/and younger than date2.
Here is my model:
public function search()
{
$criteria=new CDbCriteria;
// some code
$criteria->compare('date1',$this->date1,true);
$criteria->compare('date2',$this->date2,true);
//some code
return new CActiveDataProvider($this, array('criteria'=>$criteria));
}
Is it possible to return by criteria all records that are grater than date1, or/and lesser than date2?
I tried like this, but it doesn’t work:
public function search()
{
$criteria=new CDbCriteria;
// some code
$criteria->addCondition("(date1>=:dt1)");
$criteria->addCondition("(date2>=:dt2)");
$criteria->params[':dt1'] = this->$date1;
$criteria->params[':dt2'] = this->$date2;
//some code
return new CActiveDataProvider($this, array('criteria'=>$criteria));
}
User can add date1 and search only by date1 field, can add date2 field and search only by date2 field, can add date1 and date2 field and search date1>= date1 and date2<=date2.
If date1 and date2 is empty function returns all records.