Commit 59700e2c30676fee5d099d2e38a7c5666a5acfa4

Authored by Alexey Boroda
1 parent 575afef8

-Need to add comments

frontend/config/main.php
... ... @@ -54,6 +54,9 @@
54 54 'showScriptName' => false,
55 55 'processRoutes' => [
56 56 'page/view',
  57 + 'blog/category',
  58 + 'blog/tag',
  59 + 'blog/article',
57 60 ],
58 61 'rules' => [
59 62 '\/robots.txt' => 'site/robots',
... ...
frontend/controllers/BlogController.php
... ... @@ -3,8 +3,11 @@
3 3 namespace frontend\controllers;
4 4  
5 5 use artbox\weblog\models\Article;
  6 + use artbox\weblog\models\Category;
  7 + use artbox\weblog\models\Tag;
6 8 use yii\data\ActiveDataProvider;
7 9 use yii\web\Controller;
  10 + use yii\web\NotFoundHttpException;
8 11  
9 12 /**
10 13 * Class BlogController
... ... @@ -18,6 +21,8 @@
18 21 $query = Article::find()
19 22 ->with('lang.alias')
20 23 ->with('image')
  24 + ->with('tags.lang.alias')
  25 + ->with('category.lang.alias')
21 26 ->where([ 'status' => true ]);
22 27  
23 28 $dataProvider = new ActiveDataProvider(
... ... @@ -29,6 +34,8 @@
29 34 ]
30 35 );
31 36  
  37 + $this->view->params[ 'breadcrumbs' ][] = \Yii::t('app', 'Блог');
  38 +
32 39 return $this->render(
33 40 'index',
34 41 [
... ... @@ -37,13 +44,34 @@
37 44 );
38 45 }
39 46  
40   - public function actionCategory()
  47 + public function actionCategory(int $id)
41 48 {
  49 + /**
  50 + * @var Category $category
  51 + */
42 52 $query = Article::find()
43 53 ->with('lang.alias')
44 54 ->with('image')
45   - ->where([ 'status' => true ]);
46   -
  55 + ->with('tags.lang.alias')
  56 + ->innerJoinWith('category')
  57 + ->with('category.lang.alias')
  58 + ->where([ 'blog_category_id' => $id ]);
  59 +
  60 + $category = Category::find()
  61 + ->with('lang')
  62 + ->one();
  63 +
  64 + if (empty($category)) {
  65 + throw new NotFoundHttpException();
  66 + } else {
  67 + $this->view->params[ 'breadcrumbs' ][] = [
  68 + 'url' => [ 'blog/index' ],
  69 + 'label' => \Yii::t('app', 'Блог'),
  70 + ];
  71 +
  72 + $this->view->params[ 'breadcrumbs' ][] = $category->lang->title;
  73 + }
  74 +
47 75 $dataProvider = new ActiveDataProvider(
48 76 [
49 77 'query' => $query,
... ... @@ -52,7 +80,7 @@
52 80 ],
53 81 ]
54 82 );
55   -
  83 +
56 84 return $this->render(
57 85 'index',
58 86 [
... ... @@ -60,4 +88,69 @@
60 88 ]
61 89 );
62 90 }
  91 +
  92 + public function actionTag(int $id)
  93 + {
  94 + /**
  95 + * @var Tag $tag
  96 + */
  97 + $query = Article::find()
  98 + ->with('lang.alias')
  99 + ->with('image')
  100 + ->with('category.lang.alias')
  101 + ->innerJoinWith('tags.lang.alias')
  102 + ->where([ 'blog_tag_id' => $id ])
  103 + ->where([ 'blog_article.status' => true ]);
  104 +
  105 + $tag = Tag::find()
  106 + ->with('lang')
  107 + ->one();
  108 +
  109 + if (empty($tag)) {
  110 + throw new NotFoundHttpException();
  111 + } else {
  112 + $this->view->params[ 'breadcrumbs' ][] = [
  113 + 'url' => [ 'blog/index' ],
  114 + 'label' => \Yii::t('app', 'Блог'),
  115 + ];
  116 +
  117 + $this->view->params[ 'breadcrumbs' ][] = $tag->lang->label;
  118 + }
  119 +
  120 + $dataProvider = new ActiveDataProvider(
  121 + [
  122 + 'query' => $query,
  123 + 'pagination' => [
  124 + 'pageSize' => 3,
  125 + ],
  126 + ]
  127 + );
  128 +
  129 + return $this->render(
  130 + 'index',
  131 + [
  132 + 'dataProvider' => $dataProvider,
  133 + ]
  134 + );
  135 + }
  136 +
  137 + public function actionArticle(int $id)
  138 + {
  139 + $article = Article::find()
  140 + ->with('lang.alias')
  141 + ->with('category.lang.alias')
  142 + ->where([ 'id' => $id ])
  143 + ->one();
  144 +
  145 + if (empty($article)) {
  146 + throw new NotFoundHttpException();
  147 + }
  148 +
  149 + return $this->render(
  150 + 'article',
  151 + [
  152 + 'model' => $article,
  153 + ]
  154 + );
  155 + }
63 156 }
64 157 \ No newline at end of file
... ...
frontend/views/blog/_article.php
... ... @@ -18,8 +18,27 @@
18 18 ) ?>"><?= $model->lang->title ?></a></h2>
19 19 <div class="row">
20 20 <div class="col-sm-6">
21   - <p class="author-category"><a href="blog.html">Webdesign</a>
22   - </p>
  21 + <?php if (!empty($model->category)) { ?>
  22 + <p class="author-category"><a href="<?= Url::to(
  23 + [
  24 + 'blog/category',
  25 + 'alias' => $model->category->lang->alias,
  26 + ]
  27 + ) ?>"><?= $model->category->lang->title ?></a>
  28 + </p>
  29 + <?php } ?>
  30 +
  31 + <?php if (!empty($model->tags)) {
  32 + foreach ($model->tags as $tag) {
  33 + ?>
  34 + <p><a href="<?= Url::to(
  35 + [
  36 + 'blog/tag',
  37 + 'alias' => $tag->lang->alias,
  38 + ]
  39 + ) ?>"><?= $tag->lang->label ?></a></p>
  40 + <?php }
  41 + } ?>
23 42 </div>
24 43 <div class="col-sm-6">
25 44 <p class="date-comments">
... ... @@ -57,7 +76,7 @@
57 76 ) ?>
58 77 </a>
59 78 </div>
60   - <p class="intro"><?=$model->lang->body_preview?></p>
  79 + <p class="intro"><?= $model->lang->body_preview ?></p>
61 80 <p class="read-more"><a href="<?= Url::to(
62 81 [
63 82 'blog/article',
... ...
frontend/views/blog/article.php 0 → 100644
  1 +<?php
  2 +
  3 + use artbox\weblog\models\Article;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 +
  7 + /**
  8 + * @var View $this
  9 + * @var Article $model
  10 + */
  11 +
  12 + $this->params[ 'breadcrumbs' ][] = [
  13 + 'url' => [ 'blog/index' ],
  14 + 'label' => \Yii::t('app', 'Блог'),
  15 + ];
  16 +
  17 + $this->params[ 'breadcrumbs' ][] = $model->lang->title;
  18 +
  19 +?>
  20 +
  21 +<div id="content">
  22 + <div class="container">
  23 +
  24 + <div class="row">
  25 +
  26 + <!-- *** LEFT COLUMN ***
  27 +_________________________________________________________ -->
  28 +
  29 + <div class="col-md-9" id="blog-post">
  30 +
  31 +
  32 + <p class="text-muted text-uppercase mb-small text-right"><?php
  33 + if (!empty($model->category)) {
  34 + echo Html::a(
  35 + $model->category->lang->title,
  36 + [
  37 + 'blog/category',
  38 + 'alias' => $model->category->lang->alias,
  39 + ]
  40 + );
  41 + }
  42 + ?> | <?= date(
  43 + 'd M, Y',
  44 + $model->created_at
  45 + ) ?></p>
  46 + <p class="lead"><?= $model->lang->body_preview ?></p>
  47 +
  48 + <div id="post-content">
  49 +
  50 + <?= $model->lang->body ?>
  51 +
  52 + </div>
  53 + <!-- /#post-content -->
  54 +
  55 +<!-- <div id="comments">-->
  56 +<!-- <h4 class="text-uppercase">2 comments</h4>-->
  57 +<!-- -->
  58 +<!-- -->
  59 +<!-- <div class="row comment">-->
  60 +<!-- <div class="col-sm-3 col-md-2 text-center-xs">-->
  61 +<!-- <p>-->
  62 +<!-- <img src="img/blog-avatar2.jpg" class="img-responsive img-circle" alt="">-->
  63 +<!-- </p>-->
  64 +<!-- </div>-->
  65 +<!-- <div class="col-sm-9 col-md-10">-->
  66 +<!-- <h5 class="text-uppercase">Julie Alma</h5>-->
  67 +<!-- <p class="posted"><i class="fa fa-clock-o"></i> September 23, 2011 at 12:00 am</p>-->
  68 +<!-- <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.-->
  69 +<!-- Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>-->
  70 +<!-- <p class="reply"><a href="#"><i class="fa fa-reply"></i> Reply</a>-->
  71 +<!-- </p>-->
  72 +<!-- </div>-->
  73 +<!-- </div>-->
  74 +<!---->
  75 +<!-- -->
  76 +<!-- -->
  77 +<!-- <div class="row comment last">-->
  78 +<!-- -->
  79 +<!-- <div class="col-sm-3 col-md-2 text-center-xs">-->
  80 +<!-- <p>-->
  81 +<!-- <img src="img/blog-avatar.jpg" class="img-responsive img-circle" alt="">-->
  82 +<!-- </p>-->
  83 +<!-- </div>-->
  84 +<!-- -->
  85 +<!-- <div class="col-sm-9 col-md-10">-->
  86 +<!-- <h5 class="text-uppercase">Louise Armero</h5>-->
  87 +<!-- <p class="posted"><i class="fa fa-clock-o"></i> September 23, 2012 at 12:00 am</p>-->
  88 +<!-- <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.-->
  89 +<!-- Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>-->
  90 +<!-- <p class="reply"><a href="#"><i class="fa fa-reply"></i> Reply</a>-->
  91 +<!-- </p>-->
  92 +<!-- </div>-->
  93 +<!-- -->
  94 +<!-- </div>-->
  95 +<!---->
  96 +<!-- </div>-->
  97 +
  98 +
  99 +<!-- <div id="comment-form">-->
  100 +<!-- -->
  101 +<!-- <h4 class="text-uppercase">Leave comment</h4>-->
  102 +<!-- -->
  103 +<!-- <form>-->
  104 +<!-- <div class="row">-->
  105 +<!-- -->
  106 +<!-- <div class="col-sm-6">-->
  107 +<!-- <div class="form-group">-->
  108 +<!-- <label for="name">Name <span class="required">*</span>-->
  109 +<!-- </label>-->
  110 +<!-- <input type="text" class="form-control" id="name">-->
  111 +<!-- </div>-->
  112 +<!-- </div>-->
  113 +<!-- -->
  114 +<!-- </div>-->
  115 +<!-- -->
  116 +<!-- <div class="row">-->
  117 +<!-- <div class="col-sm-6">-->
  118 +<!-- <div class="form-group">-->
  119 +<!-- <label for="email">Email <span class="required">*</span>-->
  120 +<!-- </label>-->
  121 +<!-- <input type="text" class="form-control" id="email">-->
  122 +<!-- </div>-->
  123 +<!-- </div>-->
  124 +<!-- </div>-->
  125 +<!-- -->
  126 +<!-- <div class="row">-->
  127 +<!-- <div class="col-sm-12">-->
  128 +<!-- <div class="form-group">-->
  129 +<!-- <label for="comment">Comment <span class="required">*</span>-->
  130 +<!-- </label>-->
  131 +<!-- <textarea class="form-control" id="comment" rows="4"></textarea>-->
  132 +<!-- </div>-->
  133 +<!-- </div>-->
  134 +<!-- </div>-->
  135 +<!-- -->
  136 +<!-- <div class="row">-->
  137 +<!-- <div class="col-sm-12 text-right">-->
  138 +<!-- <button class="btn btn-template-main"><i class="fa fa-comment-o"></i> Post comment</button>-->
  139 +<!-- </div>-->
  140 +<!-- </div>-->
  141 +<!-- -->
  142 +<!-- -->
  143 +<!-- </form>-->
  144 +<!-- -->
  145 +<!-- </div>-->
  146 + <!-- /#comment-form -->
  147 +
  148 +
  149 +
  150 + </div>
  151 + <!-- /#blog-post -->
  152 +
  153 + <!-- *** LEFT COLUMN END *** -->
  154 +
  155 + <?= $this->render('_sidebar') ?>
  156 +
  157 + </div>
  158 + <!-- /.row -->
  159 +
  160 + </div>
  161 + <!-- /.container -->
  162 +</div>
  163 +<!-- /#content -->
  164 +
0 165 \ No newline at end of file
... ...