public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('title',$this->title,true); //支持模糊查找
$criteria->compare('content',$this->content,true); //支持模糊查找
$criteria->compare('type',$this->type);
$criteria->compare('user',$this->user,true); //支持模糊查找
$criteria->compare('status',$this->status);
$criteria->compare('create_data',$this->create_data,true); //支持模糊查找
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>50,
),
));
}
定义比较运算
[html] view plaincopyprint?
$criteria->compare('create_time','<='.$this->endtime),//创建早间小于等于指定时间
定义要查找的字段
[html] view plaincopyprint?
//查找的结果
$criteria->select = 'id,title,content,author,status,createtime',
//也可以以下一种方式定义
$criteria->select = array('id','title','content','author','status','createtime'),
定义填加查找条件
[html] view plaincopyprint?
//定义条件
$criteria->select = 'status=1',
//添加匹配
$criteria->compare('title',$this->title,true),
//添加条件 $condition可以是数组,也可以是字符串,and可以省略
$criteria->addCondition($condition,'and'),
//添加IN条件 $column为字段名
$criteria->addInCondition(string $column, array $values, string $operator='AND')
//添加notin条件
$criteria->addNotInCondition(string $column, array $values, string $operator='AND')
//添加like条件
$criteria->addSearchCondition(string $column, string $keyword),
//添加Between条件
$criteria->addBetweenCondition(string $column, string $valueStart, string $valueEnd, string $operator='AND'),
JOIN连表查询
[html] view plaincopyprint?
$criteria->join = 'LEFT JOIN users ON users.id=authorID',
order查询结果排序
[html] view plaincopyprint?
$criteria->order = 'createtime DESC',
group结果分组
[html] view plaincopyprint?
$criteria->group = 'projectID, teamID',
having筛选分组结果分组数量
[html] view plaincopyprint?
$criteria->having = 'SUM(revenue)<50000',
yii criteria 数据模型查询数据信息
最新推荐文章于 2021-10-09 10:21:44 发布