Ejemplo n.º 1
0
 public function actionIndex()
 {
     try {
         $q = htmlspecialchars(Yii::$app->getRequest()->get('q'));
         $model = new SearchModel();
         $models = $model->find($q)->getAllModels();
     } catch (\Exception $e) {
         \Yii::$app->getSession()->setFlash('error', 'Ошибка запроса, вероятно вы ничего не ввели!');
         $this->redirect('/');
     }
     return $this->render('index', ['models' => $models, 'q' => $q]);
 }
Ejemplo n.º 2
0
 public function actionSearch()
 {
     $searchModel = new SearchModel();
     $activeDataProvider = null;
     if (\Yii::$app->request->get('SearchModel') && $searchModel->load(\Yii::$app->request->get())) {
         if (\Yii::$app->request->isAjax) {
             return $searchModel->searchAjax();
         }
         $activeDataProvider = $searchModel->search();
     }
     return $this->render('searchResults', ['model' => $searchModel, 'resultsCount' => $searchModel->getResultsCount(), 'query' => $searchModel->terms, 'dataProvider' => $activeDataProvider]);
 }