Got a bug for CDbCriteria of YII 1.1.6

I add some attributes for CDbCriteria class, and implement a filter.

When I add the condition attribute and parmas at the begin of auto generate code, ajax search is working, but If I add the both at the end of code, ajax get request is not work,

any one meet this problem? is it a bug with the class ?




    public function search() {

        // Warning: Please modify the following code to remove attributes that

        // should not be searched.

        $criteria = new CDbCriteria;


        //condition is working when use ajax search

        $criteria->condition='project_id=:projectID'; 

        $criteria->params=array(':projectID'=>$this->project_id);


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

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

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

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

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

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

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

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

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

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

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

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




        //not working

        //$criteria->condition='project_id=:projectID'; 

        //$criteria->params=array(':projectID'=>$this->project_id);

        return new CActiveDataProvider(get_class($this), array(

            'criteria' => $criteria,

        ));

    }



It’s not a bug… it’s how it is working…

To understand this… you need to check the source of compare() method… this method adds new conditions to the condition attribute…

if you do condition=‘new condition’ after all the compare() calls… you are effectively removing all previous conditions added by the compare() methods…

But I don’t understand why are you adding this code, when you have already that with this line:


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

NOTE: moved to "Genera discussion"… please pay attention to post in proper sections of the forum…

thanks your answer!

the code




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



is auto genration code,perhaps is a condition

which is not context but only projects equal,

my filter got the approach.