/** * 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]); } }