/** * Lists all models. */ public function actionIndex() { $criteria = new CDbCriteria(); $criteria->order = 'cTime DESC'; //$criteria->select = 'id,title'; $model = new Posts(); $count = $model->count($criteria); $pager = new CPagination($count); $pager->pageSize = 100; $pager->applyLimit($criteria); $posts = $model->findAll($criteria); $this->render('index', array('pages' => $pager, 'posts' => $posts)); }
public static function searchKeyword($keyword) { $keyword = Helper::toRegularString($keyword); //paging post $model_post = new Posts(); $criteria = new CDbCriteria(); $criteria->condition = 'title like "%' . $keyword . '%" or content like "%' . $keyword . '%"'; $total = $model_post->count($criteria); $pages = new CPagination($total); $pages->pageSize = 4; $pages->applyLimit($criteria); $list = $model_post->findAll($criteria); $posts_paging = array(); $posts_paging[] = $list; $posts_paging[] = $pages; return $posts_paging; }