/** * Action для вывода каталога объектов недвижимости * * @param string $category * @param string $type * @throws CHttpException */ public function actionIndex($category, $type = '') { $realtyType = null; // Категория недвижимости $realtyCategory = RealtyCategory::model()->published()->with(['types:published'])->findByAlias($category); if (is_null($realtyCategory)) { throw new CHttpException(404); } // Тип недвижимости if (!empty($type)) { $realtyType = RealtyType::model()->published()->findByAlias($type); if (is_null($realtyType)) { throw new CHttpException(404); } } // Определение страницы для вывода мета-тегов страницы, заголовка и т.д. $page = !is_null($realtyType) ? $realtyType : $realtyCategory; // Инициализация поиска по объектам $model = new RealtyItem('user_search'); $model->unsetAttributes(); $model->category_id = $realtyCategory->id; $model->setCurrentCurrency($this->currentCurrency); if (!is_null($realtyType)) { // Подключаем EAV $model->attachEavSet($realtyType->eav_set_id); $model->type_id = $realtyType->id; } else { // Подключаем EAV $model->attachEavSet($realtyCategory->eav_set_id); } // Применение фильтра if (isset($_GET['filter'])) { $model->attributes = $_GET['filter']; $model->isSearch = true; } // Сохраняем ссылку для возврата Yii::app()->user->setState('realtyReturnUrl', $this->_constructReturnUrl('realty/realty/index')); $dataProvider = $model->user_search(); // Вывод во view if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('catalog/_catalog', ['page' => $page, 'category' => $realtyCategory, 'type' => $realtyType, 'model' => $model, 'dataProvider' => $dataProvider], false, true); } else { $this->render('index', ['page' => $page, 'category' => $realtyCategory, 'type' => $realtyType, 'model' => $model, 'dataProvider' => $dataProvider]); } }