preview.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use \app\models\News;
  3. use \app\models\base\Kd;
  4. use app\models\base\Image;
  5. $NHDataProvider = new \yii\data\ActiveDataProvider(
  6. [
  7. "query"=>\app\models\News::getNH()->limit(1),
  8. "pagination" => false
  9. ]
  10. );
  11. //print_a($NHDataProvider->query->createCommand()->rawSQL);
  12. $NH = $NHDataProvider->getModels();
  13. $newsDataProvider = new \yii\data\ActiveDataProvider(
  14. [
  15. "query"=>$model->find()->select('*')->leftJoin( 'news', 'news.id = kd.id')->where(['news.active'=>'Y'])->andWhere(['between', 'news.dt_pub', date("Y-m-d H:i:00",time()-2678400*12 ) , date("Y-m-d H:i:00")])->orderBy(["kd.order"=>SORT_ASC])->limit(6),
  16. "pagination" => false
  17. ]
  18. );
  19. $sort = $newsDataProvider->getModels();
  20. //print_a($newsDataProvider->query->createCommand()->rawSQL);
  21. $news = new \yii\data\ActiveDataProvider();
  22. $models = [];
  23. $models[] = $NH[0];//News::findOne($NH[0]->id);
  24. foreach( $sort as $item ){
  25. $models[] = News::findOne($item->id);
  26. }
  27. $news->setModels($models);
  28. Yii::$app->cache->delete('main-page-main-view');
  29. Yii::$app->cache->delete('MainPageBlock');
  30. echo \yii\helpers\Html::beginTag("div",["class"=>"main-view"]);
  31. echo \yii\widgets\ListView::widget([
  32. "dataProvider" => $news,
  33. 'options' => [
  34. 'tag' => false,
  35. 'class' => 'list-wrapper',
  36. 'id' => 'list-wrapper',
  37. ],
  38. "itemOptions"=>[
  39. "tag"=>false
  40. ],
  41. "itemView" => "@app/views/site/index/_main_view_item",
  42. "layout" => "{items}"
  43. ]);