欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

yii

程序员文章站 2022-06-14 08:04:19
...
public function search() {        $criteria = new CDbCriteria;        if(!isset($_GET['Record_sort'])){            $criteria->order = 'record_order ASC' ;        }        $criteria->compare('record_id', $this->record_id, true);        $criteria->compare('record_display', $this->record_display, true);        $criteria->compare('record_series', $this->record_series, true);        return new CActiveDataProvider($this, array(            'criteria' => $criteria,        ));    }


$criteria->compare('record_series', $this->record_series, true);这句有什么用?$criteria->compare('record_series', 'A', true);  就是where 'record_series'='A' $criteria->compare('record_series', $this->record_series, true) 加这句和没加这句,显示出的结果是一样的


回复讨论(解决方案)

$criteria->compare('record_id', $this->record_id, true);
$criteria->compare('record_display', $this->record_display, true);
$criteria->compare('record_series', $this->record_series, true);

将产生类似这样的条件表达式
record_id like '%$this->record_id%' and record_display like '%$this->record_display%' and record_series like '%$this->record_series%'
因为第三个参数你指定为 true 是模糊查询(默认是 false 精确查询)
第四个参数默认为 and

至于为什么要这么写,那是你的业务需要,别人说不了什么

相关标签: yii