/**
  * 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()]);
 }
 public function actionIndex()
 {
     $model = new UrlForm();
     $history = RequestHistory::inst();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->open();
         $this->layout = false;
         $response = Yii::$app->response;
         $response->format = \yii\web\Response::FORMAT_JSON;
         $status = 'success';
         $data = ['method' => $model->method, 'url' => $model->url, 'params' => $model->params, 'date' => $model->date, 'status_code' => $model->status, 'response' => $model->response];
         $history->add($model->method, $model->url, $model->params, $model->date);
         if ($model->error !== '') {
             $status = 'error';
             $data['error'] = $model->error;
         }
         return ['meta' => ['status' => $status], 'data' => $data];
     }
     return $this->render('index', ['model' => $model]);
 }