public function actionCreate() { if (Yii::$app->user->isGuest) { $this->redirect(['index']); } $competition = new Competition(['scenario' => 'create']); if (Yii::$app->request->isPost) { $competition->load(Yii::$app->request->post()); $competition->creator_id = Yii::$app->user->id; $competition->create(); if (!$competition->hasErrors()) { $this->redirect(['view', 'id' => $competition->id]); } } return $this->render('/competition-create', ['model' => $competition]); }
public function createPoster($uploadedPoster) { $fileName = $this->poster ? $this->poster : Yii::$app->security->generateRandomString(16); $uploadedPoster->saveAs(Competition::posterPath() . '/' . $fileName); foreach (Competition::getPosterSizes() as $size) { Image::thumbnail(Competition::posterPath() . '/' . $fileName, $size[0], $size[1])->save(Competition::posterPath() . "/{$fileName}_{$size[0]}_{$size[1]}.png"); } Image::getImagine()->open(Competition::posterPath() . '/' . $fileName)->save(Competition::posterPath() . '/' . $fileName . '.png'); unlink(Competition::posterPath() . '/' . $fileName); $this->poster = $fileName; }