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);
- 'btn btn-success']) ?> + 'btn btn-success', + 'value'=>'save', + 'name'=>'submit_save', + 'formaction' => Yii::$app->request->getUrl(), + 'formtarget' => '_self', + ]) ?>
diff --git a/common/modules/blog/views/post/post.php b/common/modules/blog/views/post/post.php index 1bd0d9c..8b5c305 100644 --- a/common/modules/blog/views/post/post.php +++ b/common/modules/blog/views/post/post.php @@ -3,7 +3,7 @@ /* @var $this yii\web\View */ /* @var $post \common\modules\blog\entities\BlogPost */ -use frontend\widgets\post\CommentsWidget; +use common\modules\blog\widgets\CommentsWidget; use yii\helpers\Html; use yii\helpers\Url; @@ -98,7 +98,7 @@ $this->registerJs($js, $this::POS_READY); - 10, 'view' => 'slider-relative', 'post' => $post, diff --git a/common/modules/blog/widgets/PostByTagsWidget.php b/common/modules/blog/widgets/PostByTagsWidget.php new file mode 100644 index 0000000..50f1003 --- /dev/null +++ b/common/modules/blog/widgets/PostByTagsWidget.php @@ -0,0 +1,42 @@ +count = $this->count ? $this->count : 5; + $this->posts = $posts; + } + + public function run(): string + { + $tag_ids = ArrayHelper::getColumn(BlogTagAssignment::find()->andWhere(['post_id' => $this->post->id])->all(), 'tag_id'); + $posts = $this->posts->getByTagsId($this->post, $tag_ids, $this->count)->getModels(); + + return $this->render($this->view, [ + 'posts' => $posts, + 'view' => $this->view, + 'url' => Url::canonical(), + ]); + } +} \ No newline at end of file diff --git a/common/modules/blog/widgets/views/slider-relative.php b/common/modules/blog/widgets/views/slider-relative.php new file mode 100644 index 0000000..c06485b --- /dev/null +++ b/common/modules/blog/widgets/views/slider-relative.php @@ -0,0 +1,38 @@ + + +
+ +
\ No newline at end of file