frontend\modules\topic\controllers\DefaultController::actionIndex PHP Метод

actionIndex() публичный Метод

话题列表
public actionIndex ( ) : mixed
Результат 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]);
    }