/**
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function run()
 {
     $section = Yii::$app->request->get('section', $this->defaultSection);
     $model = new IndexForm(['modelClass' => $this->modelClass]);
     if (!$model->loadBySection($section)) {
         HttpError::the404('Setting section not found');
     }
     $params = Yii::$app->request->post();
     if ($params) {
         $model->load($params, $model->formName());
         if ($model->save()) {
             if ($this->successCallback) {
                 call_user_func($this->successCallback, $model);
             } else {
                 Yii::$app->session->setFlash('index:success');
             }
         } else {
             if ($this->errorCallback) {
                 call_user_func($this->errorCallback, $model);
             } else {
                 Yii::$app->session->setFlash('index:error');
             }
         }
     }
     $controller = $this->controller;
     return $controller->render($this->viewFile, ['model' => $model, 'menuItems' => $this->menuItems]);
 }
 /**
  * @param $folder
  * @param $id
  * @param $name
  * @param $width
  * @param $height
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function run($folder, $id, $name, $width, $height)
 {
     $form = new ImageIndexForm(['placeholder' => $this->placeholder, 'basePath' => $this->basePath, 'baseUrl' => $this->baseUrl]);
     $form->setAttributes(['id' => $id, 'folder' => $folder, 'name' => $name, 'width' => $width, 'height' => $height]);
     if (!$form->validate() || !$form->save()) {
         HttpError::the404();
     }
     return Yii::$app->response->redirect($form->getUrl());
 }
 /**
  * Init variables
  * @throws \yii\web\HttpException
  * @throws \yii\web\NotFoundHttpException
  */
 public function afterValidate()
 {
     parent::afterValidate();
     $this->_pathRootObject = $this->basePath . DIRECTORY_SEPARATOR . $this->folder;
     $this->_urlRootObject = $this->baseUrl . DIRECTORY_SEPARATOR . $this->folder;
     if (!is_dir($this->_pathRootObject)) {
         HttpError::the404();
     }
     $this->_pathObject = $this->_pathRootObject . DIRECTORY_SEPARATOR . $this->id;
     $this->_urlObject = $this->_urlRootObject . DIRECTORY_SEPARATOR . $this->id;
     if (!is_dir($this->_pathObject) && !FileHelper::createDirectory($this->_pathObject)) {
         HttpError::the500('Can not create directory: ' . $this->_pathObject);
     }
     $this->_pathObjectFile = $this->_pathObject . DIRECTORY_SEPARATOR . $this->width . 'x' . $this->height . '_' . $this->name;
     $this->_urlObjectFile = $this->_urlObject . DIRECTORY_SEPARATOR . $this->width . 'x' . $this->height . '_' . $this->name;
     $this->_pathObjectFileOrigin = $this->_pathObject . DIRECTORY_SEPARATOR . $this->name;
     $this->_pathObjectPlaceholder = $this->_pathRootObject . DIRECTORY_SEPARATOR . $this->width . 'x' . $this->height . '_' . $this->placeholder;
     $this->_urlObjectPlaceholder = $this->_urlRootObject . DIRECTORY_SEPARATOR . $this->width . 'x' . $this->height . '_' . $this->placeholder;
     $this->_pathObjectPlaceholderOrigin = $this->_pathRootObject . DIRECTORY_SEPARATOR . $this->placeholder;
     $this->_pathRootPlaceholder = $this->basePath . DIRECTORY_SEPARATOR . $this->width . 'x' . $this->height . '_' . $this->placeholder;
     $this->_urlRootPlaceholder = $this->baseUrl . DIRECTORY_SEPARATOR . $this->width . 'x' . $this->height . '_' . $this->placeholder;
     $this->_pathRootPlaceholderOrigin = $this->basePath . DIRECTORY_SEPARATOR . $this->placeholder;
 }
 /**
  * Finding model by primary key
  * @param $pk
  * @param bool $throwException
  * @return ActiveRecord
  * @throws \yii\web\NotFoundHttpException
  */
 public function findModel($pk, $throwException = true)
 {
     /** @var ActiveRecord $model */
     $model = $this->modelClass;
     $model = $model::findOne($pk);
     if (empty($model) && $throwException) {
         HttpError::the404();
     }
     return $model;
 }