コード例 #1
0
 public function actionCreate($parent_id = 0)
 {
     $parent_id = intval($parent_id);
     $model = new Review();
     $model->loadDefaultValues();
     if (0 === $parent_id) {
         $model->parent_id = $parent_id;
         $model->submission_id = 0;
         $model->object_model_id = 0;
         $model->object_id = 0;
     } elseif (null !== ($parent = Review::findOne(['id' => $parent_id]))) {
         /** @var Review $parent */
         $model->parent_id = $parent_id;
         $model->object_id = $parent->object_id;
         $model->object_model_id = $parent->object_model_id;
         $model->root_id = $parent->root_id;
         $model->submission_id = $parent->submission_id;
     }
     if (true === Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(Url::toRoute(['view', 'id' => $model->id]));
         } else {
             // @todo add alert and may be something else here
         }
     }
     return $this->render('edit', ['review' => $model]);
 }