searchtitle.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. use app\models\news;
  3. use yii\helpers\Html;
  4. use yii\helpers\Url;
  5. use yii\grid\ActionColumn;
  6. use yii\widgets\ListView;
  7. use yii\widgets\ActiveForm;
  8. use yii\web\View;
  9. use yii\data\SqlDataProvider;
  10. /** @var yii\web\View $this */
  11. /** @var app\models\photoSearch $searchModel */
  12. /** @var yii\data\ActiveDataProvider $dataProvider */
  13. $search = trim(Yii::$app->request->get('s'));
  14. $page = trim(Yii::$app->request->get('page'));
  15. $this->title = 'Подписи фото'."-".$search;
  16. $this->params['breadcrumbs'][] = ['label' => 'Подписи фото', 'url' => ['phototitle']];
  17. $this->params['breadcrumbs'][] = $search;
  18. /*
  19. //SELECT DISTINCT SUBSTRING_INDEX(LOWER(`photo_title`),':', -1) as `ph`, count(*) FROM `news` WHERE `photo_title` != '' && `photo_title` != "''" group by ph
  20. $sql ="SELECT * FROM `news` WHERE `photo_title` like '%".$search."%' order by dt_pub";
  21. //$query = ActiveRecord::findBySql($sql);
  22. // print_r($query->asArray()->All());
  23. //$countSql = 'select count(*) ' . $sql;
  24. $dataProvider = new SqlDataProvider([
  25. 'sql' => $sql,
  26. // 'totalCount' => Yii::$app->db->createCommand($countSql)->queryScalar(),
  27. 'pagination' => [
  28. 'pageSize' => 30,
  29. ],
  30. ]);
  31. */
  32. if ($this->beginCache('fd2fsdtf_'.$page.$search, ['duration' => 3600])) {
  33. $dataProvider = new \yii\data\ActiveDataProvider(
  34. [
  35. "query"=>\app\models\front\News::find()->andWhere(['like', 'photo_title', trim($search)])->orderBy(['dt_pub'=>SORT_DESC]),
  36. 'pagination' => [
  37. 'pageSize' => 30,
  38. ],
  39. ]
  40. );
  41. ?>
  42. <div class="content">
  43. <table class="table m-0 table-hover table-striped dataTable dtr-inline">
  44. <thead>
  45. <tr>
  46. <th>фото</th>
  47. <th>дата</th>
  48. <th>Статья</th>
  49. <th>Фото подпись</th>
  50. </tr>
  51. </thead>
  52. <?= ListView::widget([
  53. 'dataProvider' => $dataProvider,
  54. 'options' => [
  55. 'tag' => "div",
  56. 'class' => 'list-wrapper',
  57. 'id' => 'list-wrapper',
  58. ],
  59. "itemOptions"=>[
  60. "tag"=>"tr",'class' => '',
  61. ],
  62. "itemView" => "_itemtitles",
  63. "layout" => "{items}\n{pager}\n{summary}",
  64. 'pager' => [
  65. 'prevPageCssClass' => 'page-item',
  66. 'firstPageLabel' => 'Начало',
  67. 'lastPageLabel' => 'Конец',
  68. 'linkOptions' => [ 'class'=>'page-link'],
  69. 'pageCssClass' => 'page-item',
  70. 'disabledListItemSubTagOptions' => ['tag' => 'a', 'class' => 'page-link'],
  71. ]
  72. ]) ?>
  73. </table>
  74. </div>
  75. <?
  76. $this->endCache();
  77. }