public function actionReply($id)
    {
        $comment = $this->findModel($id);
        if (!\Yii::$app->user->can('replyStranger', ['comment' => $comment]))
            return $this->alert(\Yii::t('app', 'Access denied.'));
        
        // fill in a new Comment
        $model = $this->newModel();
        $model->model = $comment->model;
        $model->parent_id = $comment->parent_id;
        $model->thread = $comment->thread;
        $model->user_id = \Yii::$app->user->id; // comment of a current user
        $model->status = Comment::STATUS_APPROVED; // comment approved by default
        $model->last = 1; // only the last comment in the thread can be replied

        if ($model->load(\Yii::$app->request->post()) && $model->save()) {
            // the comment to which we reply must be approved
            if ($comment->status == Comment::STATUS_PENDING) {
                $comment->status = Comment::STATUS_APPROVED;
                $comment->save(false);
            }
            return YII_DEBUG 
                ? $this->redirect(['index'])
                : $this->redirect(\Yii::$app->request->referrer);
        } else {
            return $this->renderAjax('reply', [
                'model' => $model,
                'comment' => $comment,
            ]);
        }
    }
public function actionReply($id)
    {
        $comment = $this->findModel($id);
        if (!\Yii::$app->user->can('replyStranger', ['comment' => $comment]))
            return $this->alert(\Yii::t('app', 'Access denied.'));
        
        // fill in a new Comment
        $model = $this->newModel();
        $model->model = $comment->model;
        $model->parent_id = $comment->parent_id;
        $model->thread = $comment->thread;
        $model->user_id = \Yii::$app->user->id; // comment of a current user
        $model->status = Comment::STATUS_APPROVED; // comment approved by default
        $model->last = 1; // only the last comment in the thread can be replied

        if ($model->load(\Yii::$app->request->post()) && $model->save()) {
            // the comment to which we reply must be approved
            if ($comment->status == Comment::STATUS_PENDING) {
                $comment->status = Comment::STATUS_APPROVED;
                $comment->save(false);
            }
            return YII_DEBUG 
                ? $this->redirect(['index'])
                : $this->redirect(\Yii::$app->request->referrer);
        } else {
            return $this->renderAjax('reply', [
                'model' => $model,
                'comment' => $comment,
            ]);
        }
    }
public function actionReply ( $ id ) { $ comment = $ this -> findModel ( $ id ) ; if ( ! \ Yii :: $ app -> user -> can ( 'replyStranger' , [ 'comment' => $ comment ] ) ) return $ this -> alert ( \ Yii :: t ( 'app' , 'Access denied.' ) ) ; // fill in a new Comment $ model = $ this -> newModel ( ) ; $ model -> model = $ comment -> model ; $ model -> parent_id = $ comment -> parent_id ; $ model -> thread = $ comment -> thread ; $ model -> user_id = \ Yii :: $ app -> user -> id ; // comment of a current user $ model -> status = Comment :: STATUS_APPROVED ; // comment approved by default $ model -> last = 1 ; // only the last comment in the thread can be replied if ( $ model -> load ( \ Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { // the comment to which we reply must be approved if ( $ comment -> status == Comment :: STATUS_PENDING ) { $ comment -> status = Comment :: STATUS_APPROVED ; $ comment -> save ( false ) ; } return YII_DEBUG ? $ this -> redirect ( [ 'index' ] ) : $ this -> redirect ( \ Yii :: $ app -> request -> referrer ) ; } else { return $ this -> renderAjax ( 'reply' , [ 'model' => $ model , 'comment' => $ comment , ] ) ; } }
Reply on a comment.
If creation is successful, the browser will be redirected to the 'index' page.
@return mixed
Reply on a comment . If creation is successful the browser will be redirected to the index page .