Esempio n. 1
0
 public function run()
 {
     $model = new ModelType();
     //条件
     $criteria = new CDbCriteria();
     $type_name = trim(Yii::app()->request->getParam('type_name'));
     $type_name && $criteria->addSearchCondition('type_name', $type_name);
     $criteria->order = 't.id ASC';
     $count = $model->count($criteria);
     //分页
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     //查询
     $result = $model->findAll($criteria);
     $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages));
 }
 /**
  * 模型管理
  *
  */
 public function actionIndex()
 {
     $model = new ModelType();
     $criteria = new CDbCriteria();
     $condition = '1';
     $title = $this->_request->getParam('type_name');
     $title && ($condition .= ' AND type_name LIKE \'%' . $title . '%\'');
     $criteria->condition = $condition;
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 13;
     $pageParams = $this->buildCondition($_GET, array('type_name'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     $this->render('index', array('datalist' => $result, 'pagebar' => $pages));
 }