当前位置: 动力学知识库 > 问答 > 编程问答 >

php - yii : CDbCriteria print out wrong result

问题描述:

problem : CDbCriteria print out wrong result.

This is the model search function.

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;

}

above code was print out the query when I trace with CWebLogRoute but there are no record.

Querying SQL: SELECT t.* FROM request t JOIN profiles p ON

(p.user_id = t.creator) WHERE t.reviewers LIKE :ycp1 LIMIT 10

When I change those query to following one, it was print out the records.

SELECT t.* FROM request t JOIN profiles p ON ( p.user_id =

t.creator ) WHERE t.reviewers LIKE '%3%' LIMIT 0 , 30

How can I solve the problem?

网友答案:

Try change

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

to

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

Also check format of reviewers and how it write down in the records: it's maybe record as ' 3', '3 ', or ' 3 '.

It's have to update records by update request set reviewers = trim(reviewers)

分享给朋友:
您可能感兴趣的文章:
随机阅读: