main_view.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use app\models\front\News;
  3. /*
  4. $newsDataProvider = new \yii\data\ActiveDataProvider(
  5. [
  6. "query"=>\app\models\News::getMainView()->orderBy(["dt_pub"=>SORT_DESC])->limit(3),
  7. "pagination" =>[
  8. "pageSize"=>4
  9. ],
  10. ]
  11. );
  12. */
  13. $NHDataProvider = new \yii\data\ActiveDataProvider(
  14. [
  15. "query"=>News::getNH()->limit(1),
  16. "pagination" => false
  17. ]
  18. );
  19. $NH = $NHDataProvider->getModels();
  20. $newsDataProvider = new \yii\data\ActiveDataProvider(
  21. [
  22. "query"=>\app\models\Kd::find()->orderBy(["order"=>SORT_ASC])->limit(3),
  23. "pagination" => false
  24. ]
  25. );
  26. $sort = $newsDataProvider->getModels();
  27. $news = new \yii\data\ActiveDataProvider();
  28. $models = [];
  29. if($NH[0] instanceof \app\models\front\News) $models[] = $NH[0] ;
  30. //$models[] = \app\models\News::findOne($NH[0]->id);
  31. foreach( $sort as $item ){
  32. $model = News::findOne($item->id);
  33. if($model instanceof \app\models\front\News) $models[] = $model;
  34. }
  35. $news->setModels($models);
  36. echo \yii\helpers\Html::beginTag("div",["class"=>"main-view"]);
  37. echo Yii::$app->cache->getOrSet("main-page-main-view",function () use ($news){
  38. return \yii\widgets\ListView::widget([
  39. "dataProvider" => $news,
  40. 'options' => [
  41. 'tag' => false,
  42. 'class' => 'list-wrapper',
  43. 'id' => 'list-wrapper',
  44. ],
  45. "itemOptions"=>[
  46. "tag"=>false
  47. ],
  48. "itemView" => "_main_view_item",
  49. "layout" => "{items}"
  50. ]);
  51. },News::$keysCache['main-page-main-view']);
  52. echo \yii\helpers\Html::endTag("div");