public function actionCreate($slug = null) { $model = new Category(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } else { if (isset($_FILES) && $this->module->settings['categoryThumb']) { $model->thumb = UploadedFile::getInstance($model, 'thumb'); if ($model->thumb && $model->validate(['thumb'])) { $model->thumb = Image::upload($model->thumb, 'catalog', $this->module->settings['categoryThumbWidth'], $this->module->settings['categoryThumbHeight'], $this->module->settings['categoryThumbCrop']); } else { $model->thumb = ''; } } $model->status = Category::STATUS_ON; if ($model->save()) { $this->flash('success', Yii::t('easyii/catalog', 'Category created')); return $this->redirect(['/admin/catalog/a/fields', 'id' => $model->primaryKey]); } else { $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors())); return $this->refresh(); } } } else { if ($slug) { $model->slug = $slug; } return $this->render('create', ['model' => $model]); } }