Beispiel #1
0
 public function actionAdd()
 {
     $request = \Yii::$app->request;
     $response = \Yii::$app->response;
     if ($request->get('subaction') == 'upload') {
         \app\helpers\Upload::upload(['cbSave' => function ($file, $key, $path, &$result) {
             $ex = strtolower($file->getExtension());
             if (!in_array($ex, ['jpg', 'jpeg', 'gif', 'png'])) {
                 $result[$key]['error'] = 'File extension error! Expected: jpg, jpeg, gif, png';
                 return;
             }
             $path_mid = Model::getTmpPath('tmp', $ex);
             $path_mid_abs = \Yii::getAlias("@webroot/{$path_mid}");
             Model::resizeImage('mid', $path, $path_mid_abs);
             $result[$key]['mid_src'] = \Yii::getAlias("@web/{$path_mid}");
             $sizes = Model::getPathSizes($path_mid_abs);
             $result[$key]['mid_width'] = $sizes['width'];
             $result[$key]['mid_height'] = $sizes['height'];
         }]);
     }
     $idModel = $request->get('id');
     $formModel = new Form();
     $formModel->initModel($idModel);
     $this->tryAjaxValidateModel($formModel);
     if ($request->isPost && $formModel->load($request->post()) && $formModel->validate() && $formModel->save()) {
         return $this->redirect([static::URL_TO_INDEX]);
     }
     return $this->render('add', ['formModel' => $formModel]);
 }