/** * Index page (form) * @param null $type * @return string|\yii\web\Response * @throws HttpException */ public function actionIndex($type = null) { if ($type) { $hash = null; switch ($type) { case 'file': $model = new ImageForm(); if (Yii::$app->request->isPost) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->validate()) { $hash = $model->getPHash(); } } break; case 'url': $model = new UrlForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $hash = $model->getPHash(); } break; default: throw new HttpException(404, 'Bad request'); } return $this->redirect(['site/results', 'hash' => $hash]); } return $this->render('index', ['imageForm' => new ImageForm(), 'urlForm' => new UrlForm()]); }