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]); }
public static function makeFromNode(Node $node) { return static::make($node->id, $node->user, $node->type_id, $node->time, $node->getType()->income); }