public function actionIndex()
{
$searchModel = new PlacesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$sort = new Sort([
'attributes' => [
'id' => [
'default' => SORT_ASC,
],
'price' => [
'desc' => ['lp.price' => SORT_DESC],
'asc' => ['lp.price' => SORT_ASC],
'label' => 'Цена'
],
],
]);
$all_query_result = Yii::$app->session->get('Places_search');
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'sort' => $sort
]);
}
public function search($params)
{
$query = Places::find()
->joinWith('lowerPrice as lp')
->joinWith('placePeriodRelations as pp')
->joinWith('region0 as r')
->joinWith('district0 as d')
->joinWith('placesType')
->joinWith('lowerPrice')
->joinWith('routeTypeRelation as rtr')
->where(['active' => 1])
->groupBy('pp.id_place');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
}
return $dataProvider;
<?php
echo Dropdown::widget([
'items' => [
Html::tag('li', $sort->link('price'), ['class' => 'sort-results__dropdown-item']),
],
'options' => ['class' => 'sort-results__dropdown']
]);
?>
<div class="search-results__list">
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_list',
'pager' => [
'class' => '\app\components\LinkPager',
'hideOnSinglePage' => false,
'maxButtonCount' => 3,
'prevFivePageLabel' => true,
'nextFivePageLabel' => true,
'lastPageLabel' => true,
'firstPageLabel' => true
],
'layout' => "{items}\n{pager}",
'emptyText' => '',
]); ?>
</div>