/
k6011565
/
UP09
Обзор
Документация
Войти
/
k6011565
/
UP09
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
basic/controllers/TourController.php
91 строка
2 KB
Карина Коковкина
все файлы
24 июн 2026, 15:42
24 июн 2026, 15:42
2a8b11b
Код
Авторство
О чём код?
<?php namespace app\controllers; use Yii; use yii\web\Controller; use yii\data\ActiveDataProvider; use app\models\Tour; use app\models\Review; class TourController extends Controller { public function actionIndex() { $query = Tour::find(); // Получаем параметры из GET запроса $search = Yii::$app->request->get('search'); $destination = Yii::$app->request->get('destination'); $type = Yii::$app->request->get('type'); $minPrice = Yii::$app->request->get('min_price'); $maxPrice = Yii::$app->request->get('max_price'); // Применяем фильтры if (!empty($search)) { $query->andWhere(['or', ['like', 'title', $search], ['like', 'description', $search] ]); } if (!empty($destination)) { $query->andWhere(['like', 'destination', $destination]); } if (!empty($type)) { $query->andWhere(['type' => $type]); } if (!empty($minPrice)) { $query->andWhere(['>=', 'price', $minPrice]); } if (!empty($maxPrice)) { $query->andWhere(['<=', 'price', $maxPrice]); } $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 12, ], 'sort' => [ 'defaultOrder' => [ 'created_at' => SORT_DESC, ], 'attributes' => [ 'price', 'duration', 'created_at', ], ], ]); $types = Tour::find()->select('type')->distinct()->column(); return $this->render('index', [ 'dataProvider' => $dataProvider, 'types' => $types, ]); } public function actionView($id) { $model = Tour::findOne($id); if (!$model) { throw new \yii\web\NotFoundHttpException('Тур не найден.'); } $reviews = Review::find() ->where(['tour_id' => $id]) ->with('user') ->orderBy(['created_at' => SORT_DESC]) ->all(); return $this->render('view', [ 'model' => $model, 'reviews' => $reviews, ]); } }