コード例 #1
0
 public function actionCreate($id = null)
 {
     $model = new Node();
     if ($id) {
         $base = $this->findModel($id);
         $model->time = $base->time - 1;
         $model->type_id = $base->type_id;
     } elseif (isset($_GET['type_id'])) {
         $model->type_id = (int) $_GET['type_id'];
     } else {
         $model->time = time();
     }
     $is_post = $model->load(Yii::$app->request->post());
     if ($is_post) {
         $model->count = $model->getType()->degree;
         if ($is_post && $model->validate()) {
             if ($model->save(false)) {
                 return $this->redirect(['index', 'id' => $model->id]);
             }
         } else {
             Yii::$app->session->setFlash('error', json_encode($model->errors, JSON_UNESCAPED_UNICODE));
         }
     }
     return $this->render('create', ['model' => $model]);
 }