frontend\modules\topic\controllers\DefaultController::actionView PHP Method

actionView() public method

话题详细页
public actionView ( integer $id ) : mixed
$id integer
return mixed
    public function actionView($id)
    {
        $model = Topic::findTopic($id);
        //登录才能访问的节点内容
        if (\Yii::$app->user->isGuest && in_array($model->category->alias, params('loginNode'))) {
            $this->flash('查看本主题需要登录!', 'warning');
            return $this->redirect(['/site/login']);
        }
        $dataProvider = new ActiveDataProvider(['query' => PostComment::findCommentList($id), 'pagination' => ['pageSize' => self::PAGE_SIZE], 'sort' => ['defaultOrder' => ['created_at' => SORT_ASC]]]);
        // 文章浏览次数
        Topic::updateAllCounters(['view_count' => 1], ['id' => $id]);
        //内容页面打赏
        if (in_array($model->category->alias, params('donateNode')) || array_intersect(explode(',', $model->tags), params('donateTag'))) {
            $donate = Donate::findOne(['user_id' => $model->user_id, 'status' => Donate::STATUS_ACTIVE]);
        }
        /** @var User $user */
        $user = Yii::$app->user->identity;
        $admin = $user && ($user->isAdmin($user->username) || $user->isSuperAdmin($user->username)) ? true : false;
        return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider, 'comment' => new PostComment(), 'admin' => $admin, 'donate' => isset($donate) ? $donate : []]);
    }