/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $categ = Categories::find()->all(); $model = new News(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'categ' => $categ]); } }
public function actionCreate() { $model = new News(); if ($model->load(\Yii::$app->request->post())) { if (empty($model->logo)) { $model->logo = $model->default_news_icon; } if ($model->validate() && $model->save()) { return $this->redirect(['index']); } } return $this->render('create', ['model' => $model]); }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post())) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->imageFile) { $model->image = $model->imageFile->baseName . '.' . $model->imageFile->extension; } if ($model->save()) { $model->uploadImage(); return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }
public function actionSave() { if (User::isAdmin(Yii::$app->user->identity->username)) { $model = new News(); if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { if ($model->save()) { return $this->redirect('/news/view'); } else { throw new ForbiddenHttpException('Ошибка добавления новости!', 404); } } return $this->render('save', compact('model')); } else { throw new ForbiddenHttpException('У вас нет прав администратора!', 404); } }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post())) { if (isset($_FILES) && $_FILES) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->imageFile) { $model->upload(); } } if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($sectionid) { $model = new News(); // $sections = SecNews::find()->select(['id','header'])->asArray()->all(); $sections = SecNews::find()->select(['id', 'header'])->all(); $sections = ArrayHelper::map($sections, 'id', 'header'); // echo "<pre>"; // var_dump($a); // die; $params = ['prompt' => 'Выберите секцию…']; if (isset($sectionid)) { $params['options'] = [$sectionid => ['Selected' => 'selected']]; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'sections' => $sections, 'params' => $params]); } }
/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new News(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->alias = mb_strtolower(strtr($model->title, Yii::$app->params['transliterate'])); $model->date_create = Yii::$app->formatter->asTimestamp($model->date_create . ' 12:00'); // $model->date_create = date(time()); $model->save(); // if(!empty($_FILES['UploadForm']['tmp_name']['file'])) { // $model->attachImage($_FILES['UploadForm']['tmp_name']['file'],false); // if($model->errors) { // var_dump($model->errors); // die; // } // } return $this->redirect(['update', 'id' => $model->id]); } else { // $model-> category = Category::find()->all(); // var_dump($model);die; return $this->render('create', ['model' => $model, 'category' => Category::find()->all()]); } }