Commit 04a74632 authored by Shakarim Sapa's avatar Shakarim Sapa

Merge remote-tracking branch 'origin/master'

parents ad111c06 85ebfa4c
...@@ -7,6 +7,7 @@ use common\components\BaseController; ...@@ -7,6 +7,7 @@ use common\components\BaseController;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use common\modules\blog\models\Post; use common\modules\blog\models\Post;
use common\modules\blog\models\PostTag;
/** /**
* PostController implements the CRUD actions for Post model. * PostController implements the CRUD actions for Post model.
...@@ -17,6 +18,7 @@ class PostController extends BaseController ...@@ -17,6 +18,7 @@ class PostController extends BaseController
{ {
return [ return [
'Index' => 'Блог', 'Index' => 'Блог',
'Tag' => 'Просмотр тега',
'View' => 'Просмотр записи', 'View' => 'Просмотр записи',
]; ];
} }
...@@ -36,6 +38,25 @@ class PostController extends BaseController ...@@ -36,6 +38,25 @@ class PostController extends BaseController
]); ]);
} }
/**
* Displays a single Post model.
* @param string $url
* @return mixed
*/
public function actionTag($tag)
{
$model = PostTag::find()->where(['name' => $tag])->one();
if(!$model || !$model->posts)
{
throw new NotFoundHttpException('The requested page does not exist.');
}
return $this->render('tag', [
'model' => $model,
]);
}
/** /**
* Displays a single Post model. * Displays a single Post model.
* @param string $url * @param string $url
......
...@@ -4,6 +4,8 @@ namespace common\modules\blog\models; ...@@ -4,6 +4,8 @@ namespace common\modules\blog\models;
use Yii; use Yii;
use yii\helpers\Url;
use common\modules\blog\models\Post; use common\modules\blog\models\Post;
use common\modules\blog\models\PostTagAssign; use common\modules\blog\models\PostTagAssign;
...@@ -73,4 +75,9 @@ class PostTag extends \common\components\ActiveRecordModel ...@@ -73,4 +75,9 @@ class PostTag extends \common\components\ActiveRecordModel
{ {
return $this->hasMany(PostTagAssign::className(), ['tag_id' => 'id']); return $this->hasMany(PostTagAssign::className(), ['tag_id' => 'id']);
} }
public function getUrl()
{
return Url::to(['/blog/tag/' . $this->name]);
}
} }
...@@ -22,7 +22,7 @@ use common\models\Settings; ...@@ -22,7 +22,7 @@ use common\models\Settings;
->all(); ->all();
foreach ($tags as $tag) : ?> foreach ($tags as $tag) : ?>
<a href="#" class="cat_link_mod"><?=$tag->name?></a> <a href="<?=$tag->url;?>" class="cat_link_mod"><?=$tag->name?></a>
<?php endforeach; ?> <?php endforeach; ?>
......
...@@ -40,7 +40,7 @@ use yii\helpers\Url; ...@@ -40,7 +40,7 @@ use yii\helpers\Url;
<?php foreach ($model->postTags as $tag) : ?> <?php foreach ($model->postTags as $tag) : ?>
<a href="#"># <?=$tag->name?></a> <a href="<?=$tag->url;?>"># <?=$tag->name?></a>
<?php endforeach; ?> <?php endforeach; ?>
......
<?php
use yii\helpers\Html;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model common\modules\blog\models\Post */
?>
<div class="blog_container">
<div class="container">
<div class="row">
<div class="col-md-8 col-xs-8 col-sm-12">
<section class="blog">
<h1><?=Yii::t('app', 'Tag')?>: <?=$model->name;?></h1>
<?php foreach ($model->posts as $post) : ?>
<article class="article_short">
<a href="<?=Url::to(['/blog/'.$post->url])?>" class="article_short_title"><?=$post->lang->title?></a>
<div class="article_short_head">
<span class="article_short_date"><?=date('d.m.Y', $post->created_at)?></span>
<!-- <span class="article_short_view">
180
<div class="blog_toltip_left">Количество просмотров</div>
</span> -->
<!-- <ul class="article_short_social">
<li>
<a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_fb.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_tw.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_gp.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_t.png" height="30" width="30" alt=""></a>
</li>
</ul> -->
</div>
<div class="article_short_tags">
<?php foreach ($post->postTags as $tag) : ?>
<a href="<?=$tag->url;?>"># <?=$tag->name?></a>
<?php endforeach; ?>
</div>
<div class="article_short_txt">
<?php if($post->preview) :
echo Html::img($post->preview);
endif; ?>
<?=$post->lang->text?>
</div>
</article>
<?php endforeach; ?>
<?=$this->render('_subscribe')?>
</section>
</div>
<?=$this->render('_sidebar')?>
</div>
</div>
</div>
<div class="end_keys_neft"></div>
<?=$this->render('@app/views/layouts/footer');?>
\ No newline at end of file
...@@ -35,7 +35,7 @@ use yii\helpers\Html; ...@@ -35,7 +35,7 @@ use yii\helpers\Html;
<?php foreach ($model->postTags as $tag) : ?> <?php foreach ($model->postTags as $tag) : ?>
<a href="#"># <?=$tag->name?></a> <a href="<?=$tag->url;?>"># <?=$tag->name?></a>
<?php endforeach; ?> <?php endforeach; ?>
......
...@@ -154,6 +154,7 @@ return [ ...@@ -154,6 +154,7 @@ return [
'faq/<url>' => 'faq/faq/view', 'faq/<url>' => 'faq/faq/view',
'faq' => 'faq/faq/index', 'faq' => 'faq/faq/index',
'blog' => 'blog/post/index', 'blog' => 'blog/post/index',
'blog/tag/<tag>' => 'blog/post/tag',
'blog/<url>' => 'blog/post/view', 'blog/<url>' => 'blog/post/view',
'school' => 'school/course/index', 'school' => 'school/course/index',
'school/course/<id>' => 'school/course/view', 'school/course/<id>' => 'school/course/view',
......
<?php <?php
return [ return [
'Request a call' => 'Заказать звонок', 'Request a call' => 'Заказать звонок',
'Tag' => 'Тег'
]; ];
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment