Exemplo n.º 1
0
 public function actionSearch()
 {
     $model = new SearchForm();
     $model->load(Yii::$app->request->get());
     $dataProvider = $model->search();
     return $this->render('search', ['model' => $model, 'dataProvider' => $dataProvider]);
 }
Exemplo n.º 2
0
 public function beforeAction($action)
 {
     $model = new SearchForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $q = Html::encode($model->q);
         return $this->redirect(Yii::$app->urlManager->createUrl(['site/search', 'q' => $q]));
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Lists all Books models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchForm = new SearchForm();
     $authors = Authors::getAuthorsForDropDownList();
     Yii::$app->session->set('absoluteUrl', Yii::$app->request->absoluteUrl);
     if (Yii::$app->request->isPost && $searchForm->validate()) {
         $searchForm->load(Yii::$app->request->post());
         Yii::$app->session->set('searchForm', $searchForm);
     } else {
         if (Yii::$app->session->has('searchForm')) {
             $searchForm = Yii::$app->session->get('searchForm');
         }
     }
     $query = $searchForm->getSearchQuery();
     $dataProvider = new ActiveDataProvider(['query' => $query->with('author'), 'pagination' => ['pagesize' => 10]]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchForm' => $searchForm, 'authors' => $authors]);
 }
Exemplo n.º 4
0
 public function actionBooks()
 {
     $session = Yii::$app->session;
     $search = new SearchForm();
     if ($search->load(Yii::$app->request->post()) && $search->validate()) {
         $session['search'] = Yii::$app->request->post();
     } elseif (!empty($session['search']['SearchForm'])) {
         $search->load($session['search']);
     }
     if (empty($session['search']['SearchForm'])) {
         $books = Books::find()->all();
     } else {
         $books = Books::findWithFilters($session['search']['SearchForm']);
     }
     $authors = Authors::find()->all();
     $selected_authors = array();
     foreach ($authors as $author) {
         $selected_authors[$author->id] = $author['firstname'] . " " . $author['lastname'];
     }
     return $this->render('books', ['model' => $search, 'authors' => $selected_authors, 'books' => $books]);
 }
Exemplo n.º 5
0
 public function actionSearch()
 {
     $query = RItems::find();
     $get = Yii::$app->request->get();
     $searchForm = new SearchForm();
     $searchForm->load($get);
     $query = $searchForm->setQuery($query);
     $query = $query->isActive();
     if (isset($session["GEO"])) {
         $query = $query->city($this->geo);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]);
     $items = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('search', ['items' => $items, 'pages' => $pages, 'searchForm' => $searchForm]);
 }
Exemplo n.º 6
0
 public function actionSearch()
 {
     if (!Yii::$app->user->isGuest && Yii::$app->user->identity->role == 'admin') {
         $model = new SearchForm();
         if ($model->load(Yii::$app->request->post())) {
             $query = $model->search();
         } else {
             $query = QueryModel::photos();
         }
         return $this->render('search', ['model' => $model, 'query' => $query]);
     }
     return $this->goBack();
 }
Exemplo n.º 7
0
 public function actionIndex()
 {
     $searchModel = Yii::createObject(SearchForm::className());
     $dataProvider = $searchModel->search(Yii::$app->request->get());
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
 }