/** * 首页 * */ public function actionIndex() { $model = new Post(); $criteria = new CDbCriteria(); $condition = "1=1"; $title = trim($this->_request->getParam('title')); $catalogId = intval($this->_request->getParam('catalogId')); $title && ($condition .= ' AND title LIKE \'%' . $title . '%\''); $catalogId && ($condition .= ' AND catalog_id= ' . $catalogId); $criteria->condition = $condition; $criteria->order = 't.id DESC'; $criteria->with = array('catalog'); $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; //根据title,catelogId,titleAlias查询 $pageParams = $this->buildCondition($_GET, array('title', 'catalogId')); $pages->params = is_array($pageParams) ? $pageParams : array(); $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $result = $model->findAll($criteria); //推荐位 $recom_list = RecommendPosition::model()->findAll('type=:type', array(':type' => $this->_type), array('order' => 'id')); $this->render('index', array('datalist' => $result, 'pagebar' => $pages, 'recom_list' => $recom_list)); }
/** * 查看专题 */ public function actionShow($name) { $specialModel = Special::model()->find('title_alias=:titleAlias', array('titleAlias' => CHtml::encode(strip_tags($name)))); if (false == $specialModel) { throw new CHttpException(404, '专题不存在'); } //更新浏览次数 $specialModel->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $specialModel->id)); $specialPostModel = new Post(); $criteria = new CDbCriteria(); $criteria->addCondition('t.status_is=:status AND special_id=:specialId'); $criteria->params = array('status' => 'Y', 'specialId' => $specialModel->id); $criteria->order = 't.id DESC'; $bagecmsSpecialCount = $specialPostModel->count($criteria); $postPage = new CPagination($bagecmsSpecialCount); $postPage->pageSize = 10; $postPageParams = XUtils::buildCondition($_GET, array()); $postPageParams['#'] = 'list'; $postPage->params = is_array($postPageParams) ? $postPageParams : array(); $criteria->limit = $postPage->pageSize; $criteria->offset = $postPage->currentPage * $postPage->pageSize; $specialPostList = $specialPostModel->findAll($criteria); $this->_seoTitle = empty($specialModel->seo_title) ? $specialModel->title . ' - ' . $this->_conf['site_name'] : $specialModel->seo_title; $tpl = empty($specialModel->tpl) ? 'show' : $specialModel->tpl; $data = array('specialShow' => $specialModel, 'specialPostList' => $specialPostList, 'bagecmsPagebar' => $postPage); $this->render($tpl, $data); }
/** * 获取栏目内容数据 * * @param array $params * @return array 数组 */ protected function _catalogList($params = array()) { $postModel = new Post(); $postCriteria = new CDbCriteria(); $condition = '1'; if ($params['catalog']) { $condition .= ' AND t.catalog_id=:catalogId'; $criteriaParams[':catalogId'] = intval($params['catalog']); } if ($params['keyword']) { $condition .= ' AND t.title=:title'; $criteriaParams[':title'] = CHtml::encode(strip_tags($params['keyword'])); } $condition .= " AND t.status_is='Y'"; $postCriteria->condition = $condition; $postCriteria->params = $criteriaParams; $postCriteria->order = 't.id DESC'; $postCriteria->with = 'catalog'; $count = $postModel->count($postCriteria); $postPages = new CPagination($count); $postPages->pageSize = $params['pageSize'] > 0 ? $params['pageSize'] : 20; $pageParams = XUtils::buildCondition($_GET, array('catalog', 'keyword')); $postPages->params = is_array($pageParams) ? $pageParams : array(); $postCriteria->limit = $postPages->pageSize; $postCriteria->offset = $postPages->currentPage * $postPages->pageSize; $bagecmsDataList = $postModel->findAll($postCriteria); $catalogArr = Catalog::item($params['catalog'], $this->_catalog); if ($catalogArr) { $this->_seoTitle = empty($catalogArr['catalog_name']) ? $this->_seoTitle : $catalogArr['catalog_name']; $bagecmsCatalogData = $catalogArr; $this->_seoKeywords = empty($catalogArr['seo_keywords']) ? $this->_seoKeywords : $catalogArr['seo_keywords']; $this->_seoDescription = empty($catalogArr['seo_description']) ? $this->_seoDescription : $catalogArr['seo_description']; } return array('bagecmsDataList' => $bagecmsDataList, 'bagecmsPagebar' => $postPages, 'bagecmsCatalogData' => $bagecmsCatalogData); }
/** * 首页 * */ public function actionIndex() { parent::_acl(); $model = new Post(); $criteria = new CDbCriteria(); $condition = '1'; $title = trim($this->_gets->getParam('title')); $titleAlias = trim($this->_gets->getParam('titleAlias')); $catalogId = intval($this->_gets->getParam('catalogId')); $title && ($condition .= ' AND title LIKE \'%' . $title . '%\''); $titleAlias && ($condition .= ' AND title_alias LIKE \'%' . $titleAlias . '%\''); $catalogId && ($condition .= ' AND catalog_id= ' . $catalogId); $criteria->condition = $condition; $criteria->order = 't.id DESC'; $criteria->with = array('catalog'); $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 13; $pageParams = XUtils::buildCondition($_GET, array('title', 'catalogId', 'titleAlias')); $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)); }
/** * Gets a list of posts * * @param Request $request * @param string $params * @return void */ protected static function get($request, $params) { try { $posts = Post::query($request->get('queryParams'), $request->include); } catch (OutOfBoundsException $e) { $posts = Post::findAll($request->include); } static::response($posts, 200); }
public function run() { $model = new Post(); //条件 $criteria = new CDbCriteria(); $title = trim(Yii::app()->request->getParam('title')); $catalogId = intval(Yii::app()->request->getParam('catalogId')); $criteria->addColumnCondition(array('type' => $this->controller->_type)); $title && $criteria->addSearchCondition('title', $title); $catalogId && $criteria->addColumnCondition(array('catalog_id' => $catalogId)); $criteria->order = 't.id DESC'; $criteria->with = array('catalog'); $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() { $keyword = CHtml::encode(strip_tags(trim($this->_gets->getParam('keyword')))); $postModel = new Post(); $postCriteria = new CDbCriteria(); if ($keyword) { $postCriteria->addSearchCondition('t.title', $keyword); } $postCriteria->addCondition('t.status_is=:status'); $postCriteria->params[':status'] = 'Y'; $postCriteria->with = 'catalog'; $postCriteria->order = 't.id DESC'; $bagecmsQuestionCount = $postModel->count($postCriteria); $postPages = new CPagination($bagecmsQuestionCount); $postPages->pageSize = 15; $postPageParams = XUtils::buildCondition($_GET, array('keyword')); $postPageParams['#'] = 'list'; $postPages->params = is_array($postPageParams) ? $postPageParams : array(); $postCriteria->limit = $postPages->pageSize; $postCriteria->offset = $postPages->currentPage * $postPages->pageSize; $postList = $postModel->findAll($postCriteria); $this->render('index', array('bagecmsDataList' => $postList, 'bagecmsPagebar' => $postPages)); }
function index() { $this->vars['posts'] = Post::findAll('Post', array('orderBy' => 'created_at desc')); }