if (Yii::$app->request->post('hesh_id')) {
//id хештега
$id = Yii::$app->request->post('hesh_id');
//id новостей с таким хештегом (из связной таблицы)
$news_tags = NewsTags::find()->select('news_id')->where(['tags_id' => $id])->all();
//Запихиваю все в один массив
foreach ($news_tags as $news_tag)
{
$news_id[] = $news_tag->news_id;
}
//Привожу к виду 1, 2, 3
$comma_separated = implode(",", $news_id);
//И делаю запрос
$news = News::find()->where(['in', 'id', [$comma_separated]])->all();
return debug($news);
if (Yii::$app->request->isAjax) {
if (Yii::$app->request->post('hesh_id')) {
$id = Yii::$app->request->post('hesh_id');
$tags_id = Tags::findOne($id);
$this->layout = false;
return $this->render('ajax', compact('tags_id'));
}
}
<?php $news = $tags_id->news ?>
<?php foreach ($news as $new): ?>
<?php $main_img = $new->getImage()->getUrl(); ?>
<div class="news_container">
<div class="news_img_cont" style="background: url('<?= $main_img ?>') center center no-repeat;background-size: cover;"><!--*/
/**/
/* --><img class="news_layout" id="news_lu" src="/web/img/bg/map_frame_lu.svg" alt=""><!--*/
/* --><img class="news_layout" id="news_lb" src="/web/img/bg/map_frame_lb.svg" alt=""><!--*/
/* --><img class="news_layout" id="news_rb" src="/web/img/bg/map_frame_rb.svg" alt=""><!--*/
/* --><img class="news_layout" id="news_ru" src="/web/img/bg/map_frame_ru.svg" alt=""><!--*/
/* --><div data-id = "*/<?//= $new->id ?><!--" class="fade_new"></div>-->
</div>
<div class="text_container">
<h1 class="title_new"><?= $new->name ?></h1>
<div class="tags_news">
<img src="/web/img/ICO/news/tag.svg" alt="" >
<?php $tags_c = count($new->tags); if ($tags_c == 0): ?>
<span >Разное</span>
<?php else: ?>
<? $i = 0; ?>
<?php foreach ($new->tags as $tag):?>
<span data-id = "<?= $tag->id ?>"><?= $tag->name ?><?=count($new->tags) != ++$i ? "," : ""?></span>
<?php endforeach; ?>
<?php endif; ?>
</div>
<p class="text_news"><?php $text = $new->description ?>
<?php if (strlen($text)>280)
{
$text = substr ($text, 0,strpos ($text, " ", 280)); echo $text . " ...";
}
else echo $text; ?>
</p>
<span class="data"> <?php Yii::$app->formatter->locale = 'ru-RU';
echo Yii::$app->formatter->asDate($new->date); // выведет: 1 января 2014 г. ?></span>
</div>
</div>
<?php endforeach; ?>