/** * Creates a new News model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!\Yii::$app->user->isGuest) { $model = new News(); $max = NewsSearch::find()->select('max(id_new)')->scalar() + 1; if ($model->load(Yii::$app->request->post())) { if ($model->file = UploadedFile::getInstance($model, 'file')) { $model->file->saveAs('images/new-' . $max . '.' . $model->file->extension); $model->smallimg_new = '/images/new-' . $max . '.' . $model->file->extension; } $model->save(); return $this->redirect(['view', 'id' => $model->id_new]); } else { return $this->render('create', ['model' => $model]); } } $model = new LoginForm(); if ($model->load(\Yii::$app->request->post()) && $model->login()) { $searchModel = new NewsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } else { return $this->render('login', ['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(); $loaded = $model->load(Yii::$app->request->post()); if ($loaded) { if ($model->is_published) { $model->published = date('Y-m-d H:i:s'); } } if ($loaded && $model->save()) { $model->upload(); $category_relations = $_POST['News']['categories']; foreach ($category_relations as $cat_id) { $category_relation = new CategoryRelations(); $category_relation->news_id = $model->id; $category_relation->category_id = $cat_id; $category_relation->save(); } return $this->redirect(['view', 'id' => $model->id]); } else { $categories_arr = Category::find()->asArray()->all(); foreach ($categories_arr as &$cat) { $categories[$cat['id']] = $cat['name']; } $model->is_published = 1; return $this->render('create', compact('model', 'categories')); } }
/** * 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->load($_POST); //Дата создания $model->date = date('Y-m-d'); $model->file = UploadedFile::getInstance($model, 'file'); $filename = Yii::$app->security->generateRandomString() . '.' . $model->file->extension; $model->img = $filename; $model->file->saveAs(Yii::getAlias('@app') . '/web/img/' . $filename); $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() { $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]); } }
public function actionSuggest() { $model = new News(['status' => News::STATUS_DRAFT, 'scenario' => News::SCENARIO_SUGGEST]); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('news.news_successfully_added'); return $this->redirect(['index']); } return $this->render('suggest', ['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->save()) { return Json::encode(['success' => true, 'message' => 'Created!']); } else { return Json::encode(['success' => false, 'content' => $this->renderPartial('_form', ['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->addedat = date("Y-m-d H:i:s"); $model->addedby = Yii::$app->user->identity->username; $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() { $model = new News(); if ($model->load(Yii::$app->request->post())) { if ($model->imageFile = UploadedFile::getInstance($model, 'imageFile')) { $model->upload(); } if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }
public function actionCreate() { $model = new News(); $login = new login(); $imgLoad = new imgLoad(); if (Yii::$app->user->identity->level > 1) { if ($model->load(Yii::$app->request->post()) && $model->create()) { if ($imgLoad->load(Yii::$app->request->post())) { if ($imgLoad->file = UploadedFile::getInstance($imgLoad, 'file')) { $imgLoad->img_load($model->id); $model->save_id_img($imgLoad->id); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['login' => $login, 'model' => $model, 'imgLoad' => $imgLoad]); } } }
/** * 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->url = UrlHelp::translateUrl($model->name); if ($model->validate()) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->imageFile) { if ($imgName = $model->upload($model->url)) { $model->img = $imgName; } } $model->imageFile = null; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }
public function actionCreate() { $model = new News(); // автоматически сохраняем id автора $model->author_id = Yii::$app->user->identity->id; if ($model->load(Yii::$app->request->post())) { $model->file = \yii\web\UploadedFile::getInstance($model, 'file'); if ($model->file) { $imagePath = 'uploads/'; $model->image = $imagePath . $model->file->name; } if ($model->save()) { if ($model->file) { $model->file->saveAs($model->image); } // отправляем письмо модератору с ссылкой на новую статью Yii::$app->mailer->compose()->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' Отправлено роботом'])->setTo('*****@*****.**')->setTextBody('Ссылка: http://localhost' . Yii::$app->request->BaseUrl . '/news/' . $model->id)->setSubject('Новая статья')->send(); return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }