/** * @todo: remove creates from here * @todo: make it readable, use Vacations/Dates */ public function actionCreate() { $model = new Posts(); if ($model->load(Yii::$app->request->post())) { $model->UserID = \Yii::$app->user->getId(); $model->PostType = Posts::TYPE_VACATIONS; if ($model->save()) { // todo: check the data! $hd = explode(",", Yii::$app->request->post()['holidaydates']); if (count($hd) == 2) { PostDates::deleteAll(['PostID' => $model->PostID]); $begin = new \DateTime($hd[0]); $end = new \DateTime($hd[1]); $end = $end->modify('+1 day'); $interval = new \DateInterval('P1D'); $daterange = new \DatePeriod($begin, $interval, $end); foreach ($daterange as $date) { $d = new PostDates(); $d->PostID = $model->PostID; $d->PostDate = $date->format("Y-m-d"); $d->PostDateType = 0; $d->save(); } } return $this->redirect(['vacations/index', 'username' => Yii::$app->user->identity->username]); } } else { // todo: ??? return $this->render('create', ['model' => $model, 'postdates' => []]); } }
/** * Creates a new Posts model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Posts(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->PostID]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Posts(); if ($model->load(Yii::$app->request->post())) { list($model, $imgs, $urls) = Wishlist::prepareForSave($model); $model->UserID = \Yii::$app->user->getId(); $str = iconv('UTF-8', 'windows-1251//TRANSLIT', $model->PostHeader); $str = iconv('windows-1251', 'UTF-8', $str); $model->PostURL = \frontend\models\PostWish::translit_url($str); $model->PostType = Posts::TYPE_WISH; if ($model->save()) { Wishlist::insertUrlsAndImgs($model->PostID, $imgs, $urls); return $this->redirect(['wishlist/index', 'username' => Yii::$app->user->identity->username]); } } else { return $this->render('create', ['model' => $model, 'posturls' => [], 'postimgs' => []]); } }