/** * Creates a new Projects model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Projects(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->project_id]); } else { return $this->render('create', ['model' => $model]); } }
public function saveAction() { if (!$this->isXmlHttpRequest()) { throw new \Exception('Неверный тип запроса!'); } $projectsModel = new Projects(); $data = $this->request->getPost(); if (!isset($data['id']) || !isset($data['action']) || !isset($data['name']) || !isset($data['description']) || !isset($data['date_deadline'])) { throw new \Exception('Неверный тип запроса!'); } $data['id'] = (int) $data['id']; $data['name'] = trim($data['name']); $data['description'] = trim($data['description']); $data['date_deadline'] = trim($data['date_deadline']); if ($data['name'] == '' || $data['date_deadline'] == '') { throw new \Exception('Вы заполнили не все необходимые поля!'); } unset($data['action']); $data['id'] = $projectsModel->save($data); $project = $projectsModel->getProjectsDataById($data['id']); $this->view->project = $project; $user = $this->session->getCurrentUser(); $this->view->user = $user; }