/** * 查看推荐的内容 * @param unknown $id */ public function actionView($id) { //推荐位 $recomPosition = RecommendPosition::model()->findByPk($id); //内容类型 $type = ModelType::model()->findByPk($recomPosition->type); //模型表 $table = $type->model; $content = new Recommend(); $criteria = new CDbCriteria(); $condition = '1 = 1'; $id = $this->_request->getParam('id'); $title = $this->_request->getParam('title'); $id && ($condition .= ' AND t.id =' . $id); $title && ($condition .= " AND {$table}.title like '%{$title}%'"); $criteria->condition = $condition; $criteria->with = array($table); $count = $content->count($criteria); $pages = new CPagination($count); $pages->pageSize = 20; $pageParams = $this->buildCondition($_GET, array('id', 'title')); $pages->params = is_array($pageParams) ? $pageParams : array(); $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $result = $content->findAll($criteria); $this->render('view', array('datalist' => $result, 'table' => $table, 'recom_position' => $recomPosition, 'pagebar' => $pages)); }