/** * Creates a new Page model. Categories and tags associated with article should * be inserted in pivot tables. Image file should be uploaded to images folder. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); $model->scenario = 'create'; $tagsToArray = []; if ($model->load(Yii::$app->request->post())) { $model->avatar = UploadedFile::getInstance($model, 'avatar'); if ($model->avatar !== null) { $model->cover_image = Yii::$app->security->generateRandomString(8) . '.' . $model->avatar->extension; } $model->user_id = Yii::$app->user->identity->id; if ($model->save()) { $dest = Yii::getAlias('@frontend/web/images/blog'); if ($model->avatar !== null) { $model->avatar->saveAs($dest . '/' . $model->cover_image); } if (Yii::$app->request->post('Page')['categoriesFromSelect']) { $categories = Yii::$app->request->post('Page')['categoriesFromSelect']; $this->insertPageCategories($categories, $model); } if (Yii::$app->request->post('Page')['tag_title']) { $tagsToArray = explode(',', Yii::$app->request->post('Page')['tag_title']); $this->checkTags($tagsToArray, $model); } Yii::$app->session->setFlash('message', 'The article has been created successfully.'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed * @throws \yii\base\InvalidParamException */ public function actionCreate() { $model = new Page(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'project_id' => Yii::$app->request->get('project_id')]); } else { $model->project_id = Yii::$app->request->get('project_id'); return $this->render('create', ['model' => $model]); } }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); $pageList = Page::find()->select(['id', 'header', 'pid'])->asArray()->all(); $pageList = Tree::header($pageList); $pageList = ArrayHelper::map($pageList, 'id', 'header'); $paramsPageList = ['prompt' => 'Эта страница будет родительская', 'encode' => false, 'size' => 20]; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'pageList' => $pageList, 'paramsPageList' => $paramsPageList]); } }
public function actionCreate($catid = 0) { $model = new Page(); $model->category_id = $catid; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { $locals = []; $locals['model'] = $model; $locals['catid'] = $catid; $locals['categories'] = PageCategory::getAllCategories(); $locals['tpls'] = CommonUtility::getFrontViews('page', 'detail_'); return $this->render('create', $locals); } }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->Response->format = 'json'; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { $model->created_dt = date('Y-m-d'); $model->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
public function actionUpdate($id) { if ($id) { $model = Page::findOne($id); if (!$model) { throw new NotFoundHttpException(); } } else { $model = new Page(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->addFlash('success', 'Страница сохранена'); return $this->redirect(['index']); } return $this->render('update', ['model' => $model]); }
/** * Creates a new Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); $model->allowComment = true; $model->allowFeed = true; $model->allowPing = true; if (Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post())) { $model->inputAttachments = Yii::$app->request->post('inputAttachments', []); if ($model->save()) { return $this->redirect(['index']); } } } return $this->render('create', ['model' => $model]); }
/** * Creates a new PageData model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new PageData(); $page = new Page(); $model->setScenario('create'); if (Yii::$app->request->isPost) { $page->load(Yii::$app->request->post()); $model->load(Yii::$app->request->post()); if ($page->validate()) { $model->id_page = $page->id; if ($page->save() && $model->save()) { return $this->redirect(['index']); } } } return $this->render('create', ['page' => $page, 'model' => $model]); }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Page(); $model->created_by = Yii::$app->user->id; $task = Yii::$app->request->post('task', 'save'); if ($model->load(Yii::$app->request->post())) { //$model = $this->uploadFoto($model); if ($model->uploadFoto() === false) { Yii::$app->session->setFlash('error', 'Ошибка загрузки фото'); } $model->save(); Yii::$app->session->setFlash('success', 'Saved'); if ($task == 'apply') { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->redirect(['index']); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }