コード例 #1
0
 /**
  * Creates a new SptComment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new SptComment();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
 /**
  * Displays a single SptTask model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     if (isset($_POST['progress'])) {
         $model->progress = $_POST['progress'];
         $model->save();
         \Yii::$app->session->setFlash('success', 'Save progress success');
     }
     $comment = new \ivoglent\simpletask\models\SptComment(['task_id' => $model->id, 'user_id' => \Yii::$app->user->identity->id]);
     if ($comment->load(\Yii::$app->request->post())) {
         if ($comment->save()) {
             \Yii::$app->session->setFlash('success', 'Comment success');
         } else {
             print_r($model->getErrors());
         }
     }
     $commentProvider = new ActiveDataProvider(['query' => SptComment::find()->where(['task_id' => $id])]);
     return $this->render('view', ['model' => $model, 'commentProvider' => $commentProvider, 'comment' => $comment]);
 }