/** * Creates a new Work model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Work(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'kpi' => $model->kpi, 'prov' => $model->prov]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Work model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed * @throws NotFoundHttpException */ public function actionAdd() { if (!Yii::$app->user->can('addWork')) { throw new NotFoundHttpException('The requested page does not exist.'); } if (!Yii::$app->user->can('editWork') && Yii::$app->user->identity->countWorks()) { return $this->redirect(['user/profile']); } $model = new Work(['scenario' => 'add']); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->uploadFiles()) { $model->save(false); \Yii::$app->getSession()->setFlash('success', 'Работа добавлена'); return $this->redirect(['user/profile']); } else { return $this->render('create', ['model' => $model]); } }