是否可以在 yii 比较中使用 IN 条件


Is it possible to use IN conditions in yii compare

嗨,我正在尝试使用 yii 创建一个搜索功能CDbCriteria一切都可以.但是当我输入全名 .i.e 时manoj dhiman我已将其保存为 firstname 并在数据库中lastname.所以我分解了搜索的键,所以我需要类似的东西,以便我可以用该数组的 compere 搜索结果.我的代码是

public function actionSearchuser()
    {
        $key=$_POST['key'];
        $data=array();
        if($key)
        {
            $users=explode(' ',$key);   // the users array 
            $model=new Goals;
            $model->attributes = $_POST['key'];
            $criteria = new CDbCriteria();
            $criteria->with='profile';
            $criteria->distinct=true;
            //$criteria->addInCondition('firstname',$users);
            $criteria->compare('firstname', $key, true, 'OR');
            $criteria->compare('school', $key, true, 'OR');
            $criteria->compare('occupation', $key, true, 'OR');
            $criteria->compare('location', $key, true, 'OR');
            $criteria->compare('lastname', $key, true, 'OR');
            $criteria->compare('username', $key, true, 'OR');
            $criteria->compare('email', $key, true, 'OR');

             $dataProvider=new CActiveDataProvider('User', array(
                'criteria' => $criteria
        ));
            $data=$dataProvider->getData();
        }
        $this->renderPartial('Searchuser',array('data'=>$data));
    }

我也尝试了$criteria->addInCondition('firstname',$users);,但是将整个键与名称匹配。我要like.怎么可能?

谢谢

在疯狂的骷髅的评论之后,它对我有用. $criteria->compare('concat(firstname, " ", lastname)', $key, true, 'OR');参考

资料
public function actionSearchuser()
    {
        $key=$_POST['key'];
        $data=array();
        if($key)
        {
            $users=explode(' ',$key);
            $model=new Goals;
            $model->attributes = $_POST['key'];
            $criteria = new CDbCriteria();
            $criteria->with='profile';
            $criteria->distinct=true;
            //$criteria->addInCondition('firstname',$users);
            $criteria->compare('firstname', $key, true, 'OR');
            $criteria->compare('concat(firstname, " ", lastname)', $key, true, 'OR');
            $criteria->compare('school', $key, true, 'OR');
            $criteria->compare('occupation', $key, true, 'OR');
            $criteria->compare('location', $key, true, 'OR');
            $criteria->compare('lastname', $key, true, 'OR');
            $criteria->compare('username', $key, true, 'OR');
            $criteria->compare('email', $key, true, 'OR');

             $dataProvider=new CActiveDataProvider('User', array(
                'criteria' => $criteria
        ));
            $data=$dataProvider->getData();
        }
        $this->renderPartial('Searchuser',array('data'=>$data));
    }