Beispiel #1
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]);
 }