Yii Model Search, Cdbcriteria With Compare And Condition

Hello

i am currently trying to improve my search functionality by allowing users to find items added to the database between two dates i am doing this using the following code:





		$criteria=new CDbCriteria;

		$criteria->with = array( 'customer', 'userAssign');


		$criteria->compare('taskID',$this->taskID);

		$criteria->compare('createdBy',$this->createdBy);

		$criteria->compare('statusID',$this->statusID,true);

		$criteria->compare('priorityID',$this->priorityID);

		$criteria->compare('created',$this->created,true);

		$criteria->compare('updated',$this->updated,true);

		$criteria->compare('closed',$this->closed,true);

		$criteria->compare('assignedUser',$this->assignedUser);

		$criteria->compare('subject',$this->subject,true);

		$criteria->compare('Description',$this->Description,true);

		$criteria->compare('Email',$this->Email);

		$criteria->compare('unassigned',$this->unassigned,true);


		if(!empty($this->date_from) && !empty($this->date_to)){

		  $criteria->condition="`created` Between '$this->date_from' And '$this->date_to'";

		}




Which is working fine but when a date_from and date_to is chosen on the search form other compare values entered are ignored such as is you choose a status. Am i right in thinking that you cannot mix cdbcriteria compare and condition? and if this is the case how else can this be achieved?

Thanks in advance

Ok so i have now changed it to this:




		if(!empty($this->date_from) && !empty($this->date_to)){

		  $criteria->addCondition("`created` Between '$this->date_from' And '$this->date_to'", 'AND');

		}



Which seems to work ok…