Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii CGridView上的多列搜索_Php_Search_Yii_Cgridview - Fatal编程技术网

Php Yii CGridView上的多列搜索

Php Yii CGridView上的多列搜索,php,search,yii,cgridview,Php,Search,Yii,Cgridview,我有管理页面包含CGridView并与用户数据库连接,我需要使CGridView上的搜索工作在多栏,而不仅仅是一个。。像这样: 我需要通过电话号码、用户名或电子邮件地址查找用户信息,可以吗?我的代码在图片下面: 代码 用户模型: 我用过或,但这不是工作。。我仍然只按名字搜索 public function search() { // @todo Please modify the following code to remove attributes that should not b

我有管理页面包含CGridView并与用户数据库连接,我需要使CGridView上的搜索工作在多栏,而不仅仅是一个。。像这样:

我需要通过电话号码、用户名或电子邮件地址查找用户信息,可以吗?我的代码在图片下面:

代码

用户模型: 我用过或,但这不是工作。。我仍然只按名字搜索

public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('full_name',$this->full_name,'OR');
    $criteria->compare('full_name',$this->landline,'OR');
    $criteria->compare('full_name',$this->mobile_number,'OR');
    $criteria->compare('email_address',$this->email_address,true);
    $criteria->compare('city',$this->city,true);


    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
        'sort'=>array(
            'defaultOrder'=>'id DESC',
        )
    ));
}

你在比较中犯了点小错误

$criteria->compare('full_name', $this->full_name, true, 'OR');
$criteria->compare('landline', $this->full_name, true, 'OR');
$criteria->compare('mobile_number', $this->full_name, true, 'OR');
第一个参数是数据库中的字段,第二个参数是您在表单中填写的内容。 您还跳过了允许部分匹配的第三个参数。 第四个参数必须是“或”

请记住,这是一种解决方法,如果您不小心,以后可能会遇到一些麻烦,因为您正在将
固定电话
移动电话
存储到
$model->全名

我建议您在用户模式中添加另一个属性,比如
User\u info
,然后使用该属性存储来自请求的输入,并将其与数据库进行比较


上面的示例仍然有效,如果您希望使用附加参数改进代码,但找不到解决方法,我会更好地解释,只需大声喊叫。

我认为这在中是不可能的Yii@bad_boy这是检查答案:)