From 59700e2c30676fee5d099d2e38a7c5666a5acfa4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 27 Sep 2017 12:14:49 +0300 Subject: [PATCH] -Need to add comments --- frontend/config/main.php | 3 +++ frontend/controllers/BlogController.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- frontend/views/blog/_article.php | 25 ++++++++++++++++++++++--- frontend/views/blog/article.php | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 286 insertions(+), 7 deletions(-) create mode 100644 frontend/views/blog/article.php diff --git a/frontend/config/main.php b/frontend/config/main.php index 3c2719f..fcb3e70 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -54,6 +54,9 @@ 'showScriptName' => false, 'processRoutes' => [ 'page/view', + 'blog/category', + 'blog/tag', + 'blog/article', ], 'rules' => [ '\/robots.txt' => 'site/robots', diff --git a/frontend/controllers/BlogController.php b/frontend/controllers/BlogController.php index 94c4b95..ed433f9 100644 --- a/frontend/controllers/BlogController.php +++ b/frontend/controllers/BlogController.php @@ -3,8 +3,11 @@ namespace frontend\controllers; use artbox\weblog\models\Article; + use artbox\weblog\models\Category; + use artbox\weblog\models\Tag; use yii\data\ActiveDataProvider; use yii\web\Controller; + use yii\web\NotFoundHttpException; /** * Class BlogController @@ -18,6 +21,8 @@ $query = Article::find() ->with('lang.alias') ->with('image') + ->with('tags.lang.alias') + ->with('category.lang.alias') ->where([ 'status' => true ]); $dataProvider = new ActiveDataProvider( @@ -29,6 +34,8 @@ ] ); + $this->view->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Блог'); + return $this->render( 'index', [ @@ -37,13 +44,34 @@ ); } - public function actionCategory() + public function actionCategory(int $id) { + /** + * @var Category $category + */ $query = Article::find() ->with('lang.alias') ->with('image') - ->where([ 'status' => true ]); - + ->with('tags.lang.alias') + ->innerJoinWith('category') + ->with('category.lang.alias') + ->where([ 'blog_category_id' => $id ]); + + $category = Category::find() + ->with('lang') + ->one(); + + if (empty($category)) { + throw new NotFoundHttpException(); + } else { + $this->view->params[ 'breadcrumbs' ][] = [ + 'url' => [ 'blog/index' ], + 'label' => \Yii::t('app', 'Блог'), + ]; + + $this->view->params[ 'breadcrumbs' ][] = $category->lang->title; + } + $dataProvider = new ActiveDataProvider( [ 'query' => $query, @@ -52,7 +80,7 @@ ], ] ); - + return $this->render( 'index', [ @@ -60,4 +88,69 @@ ] ); } + + public function actionTag(int $id) + { + /** + * @var Tag $tag + */ + $query = Article::find() + ->with('lang.alias') + ->with('image') + ->with('category.lang.alias') + ->innerJoinWith('tags.lang.alias') + ->where([ 'blog_tag_id' => $id ]) + ->where([ 'blog_article.status' => true ]); + + $tag = Tag::find() + ->with('lang') + ->one(); + + if (empty($tag)) { + throw new NotFoundHttpException(); + } else { + $this->view->params[ 'breadcrumbs' ][] = [ + 'url' => [ 'blog/index' ], + 'label' => \Yii::t('app', 'Блог'), + ]; + + $this->view->params[ 'breadcrumbs' ][] = $tag->lang->label; + } + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 3, + ], + ] + ); + + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + ] + ); + } + + public function actionArticle(int $id) + { + $article = Article::find() + ->with('lang.alias') + ->with('category.lang.alias') + ->where([ 'id' => $id ]) + ->one(); + + if (empty($article)) { + throw new NotFoundHttpException(); + } + + return $this->render( + 'article', + [ + 'model' => $article, + ] + ); + } } \ No newline at end of file diff --git a/frontend/views/blog/_article.php b/frontend/views/blog/_article.php index ecdb23d..7cb7307 100644 --- a/frontend/views/blog/_article.php +++ b/frontend/views/blog/_article.php @@ -18,8 +18,27 @@ ) ?>">lang->title ?>
-

Webdesign -

+ category)) { ?> +

category->lang->title ?> +

+ + + tags)) { + foreach ($model->tags as $tag) { + ?> +

lang->label ?>

+

@@ -57,7 +76,7 @@ ) ?>

-

lang->body_preview?>

+

lang->body_preview ?>

+

+ +
+ + \ No newline at end of file -- libgit2 0.21.4