public function actionView($slug) { $news = News::get($slug); if (!$news) { throw new \yii\web\NotFoundHttpException('News not found.'); } //return $this->render('view', [ // 'news' => $news //]); return $this->render('index', ['news' => News::items(['pagination' => ['pageSize' => 5]]), 'currentNews' => $news]); }
?> <?php echo Html::a('[Подробно]', ['site/news', 'slug' => $lastNews->slug], ['class' => 'more-link']); ?> </p> </div> </div> </div> </div> <div class="container"> <div class="row"> <div class="col col-9 news-content news-block"> <h2>Свежие новости</h2> <?php foreach (News::items() as $newsItem) { ?> <div> <?php echo Html::a($newsItem->title, ['site/news', 'slug' => $newsItem->slug]); ?> <small>[<?php echo date('Y-m-d', $newsItem->time); ?> ]</small> </div> <?php } ?>
public function actionIndex($tag = null) { return $this->render('index', ['news' => News::items(['tags' => $tag, 'pagination' => ['pageSize' => 2]])]); }