lenta.php 902 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. use app\models\News;
  3. use yii\data\ActiveDataProvider;
  4. $newsDataProvider = new ActiveDataProvider([
  5. "query"=>News::find(),
  6. 'sort'=> [
  7. 'defaultOrder' => ['dt_pub' => SORT_DESC],
  8. ],
  9. "pagination" =>[
  10. "pageSize"=>70
  11. ],
  12. ]);
  13. ?>
  14. <a class="news-link" href="/news">Лента новостей</a>
  15. <div class="lenta">
  16. <?= Yii::$app->cache->getOrSet("main_page_lenta",function () use ($newsDataProvider){
  17. return \yii\widgets\ListView::widget([
  18. "dataProvider"=>$newsDataProvider,
  19. 'options' => [
  20. 'tag' => 'div',
  21. 'class' => 'list-wrapper',
  22. 'id' => 'list-wrapper',
  23. ],
  24. "layout" => "{items}",
  25. "itemView"=> "/layouts/lenta/_item"
  26. ]);
  27. },120);
  28. ?>
  29. <div class="all-news">
  30. <a href="/news">Все новости</a>
  31. </div>
  32. </div>