Example #1
0
 /**
  * Finds the PostMeta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PostMeta the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PostMeta::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
 /**
  * 话题列表
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     // 话题或者分类筛选
     $params = Yii::$app->request->queryParams;
     empty($params['tag']) ?: ($params['PostSearch']['tags'] = $params['tag']);
     if (isset($params['node'])) {
         $postMeta = PostMeta::findOne(['alias' => $params['node']]);
         $postMeta ? $params['PostSearch']['post_meta_id'] = $postMeta->id : '';
     }
     $dataProvider = $searchModel->search($params);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => 'topic', 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     // 排序
     $sort = $dataProvider->getSort();
     $sort->attributes = array_merge($sort->attributes, ['hotest' => ['asc' => ['comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'excellent' => ['asc' => ['status' => SORT_DESC, 'comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'uncommented' => ['asc' => ['comment_count' => SORT_ASC, 'created_at' => SORT_DESC]]]);
     return $this->render('index', ['searchModel' => $searchModel, 'sorts' => $this->sorts, 'dataProvider' => $dataProvider]);
 }
Example #3
0
 /**
  * Update meta data for current post.
  *
  * @param $meta_name
  * @param $meta_value
  *
  * @return bool
  */
 public function upMeta($meta_name, $meta_value)
 {
     /* @var $model \common\models\PostMeta */
     $model = PostMeta::findOne(['meta_name' => $meta_name, 'post_id' => $this->id]);
     if (is_array($meta_value) || is_object($meta_value)) {
         $meta_value = Json::encode($meta_value);
     }
     $model->meta_value = $meta_value;
     return $model->save();
 }