0

问题:CDbCriteria 打印出错误的结果。

这是模型搜索功能。

public function summary()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;
        $criteria->select = 't.*';

        if (Yii::app()->user->checkAccess('Reviewer')):
            $criteria->addSearchCondition('t.reviewers',Yii::app()->user->id,false, 'AND');
        endif;

        if (Yii::app()->user->checkAccess('Implementer')):
            $criteria->addSearchCondition('t.implementers',Yii::app()->user->id,false, 'OR');
        endif;

        if (Yii::app()->user->checkAccess('Creator')):
            $criteria->compare('t.creator',Yii::app()->user->id, false, 'OR');
        endif;

        $criteria->compare('request_type_id',$this->request_type_id);
        $criteria->compare('request_category_id',$this->request_category_id);
        $criteria->compare('financial_type_id',$this->financial_type_id);
        $criteria->compare('urgency_id',$this->urgency_id);
        $criteria->compare('eta_date',$this->eta_date,true);

        if (Yii::app()->user->checkAccess('Reviewer') || Yii::app()->user->checkAccess('Implementer')):
            $criteria->join   = "JOIN profiles p ON (p.user_id = t.creator)";
            if($this->creator):
                $criteria->addSearchCondition('p.firstname',$this->creator, true, 'AND');
            endif;
        endif;

        if(isset($this->status)):
            $criteria->compare('t.status',$this->status);
        endif;



        $data = new CActiveDataProvider(get_class($this), array(
                'criteria'=>$criteria,
                'pagination'=>false,
        ));
        $_SESSION['all'] = $data;


        $data = new CActiveDataProvider(get_class($this), array(
                'pagination'=>array('pageSize'=> Yii::app()->user->getState('pageSize',
                        Yii::app()->params['defaultPageSize']),),
                'criteria'=>$criteria,
        ));
        $_SESSION['limited'] = $data; 

        return $data;
    }

当我使用 CWebLogRoute 进行跟踪但没有记录时,上面的代码打印出查询。

查询 SQL:SELECT t.* FROM request tJOIN profiles p ON (p.user_id = t.creator) WHERE t.reviewers LIKE :ycp1 LIMIT 10

当我将这些查询更改为以下查询时,它会打印出记录。

SELECT t.* FROM request t JOIN profiles p ON (p.user_id = t.creator) WHERE t.reviewers LIKE '%3%' LIMIT 0 , 30

我该如何解决这个问题?

4

1 回答 1

1

尝试改变

$criteria->addSearchCondition('t.reviewers',Yii::app()->user->id,false, 'AND');

$criteria->addSearchCondition('t.reviewers',Yii::app()->user->id, true, 'AND');

还要检查记录的格式reviewers和记录方式:它可能记录为“3”、“3”或“3”。

它必须通过以下方式更新记录update request set reviewers = trim(reviewers)

于 2012-11-18T17:11:42.920 回答