Пример #1
0
 /**
  * Creates a new Comment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Comment();
     if (isset($_POST['Comment'])) {
         $model->attributes = $_POST['Comment'];
         $model->setAttribute('id', $model->id);
         $model->setAttribute('nama', Yii::$app->user->identity->nama);
         $model->setAttribute('post_id', Yii::$app->session['post_id']);
         $model->setAttribute('isi', $model->isi);
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', 'Komentar Anda telah ditambahkan');
             $this->redirect(['post/view', 'id' => $model->post_id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }