Home >Backend Development >PHP Tutorial >yii
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
至于为什么要这么写,那是你的业务需要,别人说不了什么