diff --git a/common/modules/blog/controllers/PostController.php b/common/modules/blog/controllers/PostController.php index 64bd745..e5775db 100644 --- a/common/modules/blog/controllers/PostController.php +++ b/common/modules/blog/controllers/PostController.php @@ -214,11 +214,12 @@ class PostController extends FrontendController $post->image = $filename; } - $path = $post->getUploadedFilePath('image'); - FileHelper::createDirectory(pathinfo($path, PATHINFO_DIRNAME), 0775, true); - $post->image->saveAs($path); - - $post->image = $post->getImageFileUrl('image'); + if ($post->image && !is_string($post->image)) { + $path = $post->getUploadedFilePath( 'image' ); + FileHelper::createDirectory( pathinfo( $path, PATHINFO_DIRNAME ), 0775, true ); + $post->image->saveAs( $path ); + $post->image = $post->getImageFileUrl( 'image' ); + } return $this->render('post', [ 'post' => $post, diff --git a/common/modules/blog/controllers/manage/PostController.php b/common/modules/blog/controllers/manage/PostController.php index 43cad3f..0a6fc2f 100644 --- a/common/modules/blog/controllers/manage/PostController.php +++ b/common/modules/blog/controllers/manage/PostController.php @@ -87,6 +87,7 @@ class PostController extends Controller public function actionCreate() { $form = new BlogPostForm(); + $form->action = 'create'; $form->published_at = date('d.m.Y H:i:s'); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { @@ -112,6 +113,7 @@ class PostController extends Controller { $post = $this->findModel($id); $form = new BlogPostForm($post); + $form->action = 'update'; $form->published_at = date('d.m.Y H:i:s', $form->published_at); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { diff --git a/common/modules/blog/forms/BlogPostForm.php b/common/modules/blog/forms/BlogPostForm.php index eb03dbe..19a5349 100644 --- a/common/modules/blog/forms/BlogPostForm.php +++ b/common/modules/blog/forms/BlogPostForm.php @@ -17,6 +17,8 @@ use Yii; */ class BlogPostForm extends CompositeForm { + public $action; + public $category_id; public $title; public $description; diff --git a/common/modules/blog/views/manage/post/_form.php b/common/modules/blog/views/manage/post/_form.php index c5988f0..6be3c16 100644 --- a/common/modules/blog/views/manage/post/_form.php +++ b/common/modules/blog/views/manage/post/_form.php @@ -149,7 +149,13 @@ $this->registerJs($js2);