//接收GET传值
$name = Yii::app()->request->getQuery(‘name’);
$age = Yii::app()->request->getQuery(‘age’);
$criteria = new CDbCriteria();
//拼装查询条件
if (!empty($name)) {
$criteria->addCondition(‘name like :name’);
$criteria->params[‘:name’] = ‘%’ . $name . ‘%’;
}
if (!empty($age)) {
$criteria->addCondition(‘age = :age’);
$criteria->params[‘:age’] = $age;
}
//分页
$page = new CPagination();
$page->pageSize = 20;
$page->itemCount = User::model()->count($criteria);
$page->applyLimit($criteria);
//排序
$criteria->order = ‘id Desc’;
//查询数据
$users = User::model()->findAll($criteria);
//加载视图
$this->render(‘index’, array(
‘data’ => $data,
‘page’ => $page,
));