/** * Creates a new Route model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $rootPath = Yii::$app->params['route_img_dir']; $model = new Route(); $status = Lookup::items("RouteStatus"); if ($model->load(Yii::$app->request->post())) { $image = UploadedFile::getInstance($model, 'img'); $ext = $image->getExtension(); $randName = time() . rand(1000, 9999) . "." . $ext; $path = abs(crc32($randName) % 500); $rootPath = $rootPath . "img/"; if (!file_exists($rootPath)) { mkdir($rootPath, 0777, true); } $image->saveAs($rootPath . $randName); $model->img = $rootPath . $randName; if ($model->save()) { $is_joined = Join::find()->andWhere(['user_id' => $model->author_id, 'route_id' => $model->id])->all() == null; if ($is_joined) { $join = new Join(); $join->user_id = $model->author_id; $join->route_id = $model->id; $join->save(); } return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model, 'status' => $status]); } }
/** * Creates a new Route model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Route(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }