$book_id, 'status' => 0 ]); $book = Book::find()->with('author')->where(['id' => $book_id])->one(); if ($model->load(\Yii::$app->request->post()) and $model->save()){ \Yii::$app->session->setFlash('success', 'Дякуємо за ваш запит. Найближчим часом, наш менеджер зв\'яжеться з Вами для уточнення деталей'); return $this->redirect(['site/index']); } return $this->render('index', [ 'model' => $model, 'book' => $book ]); } public function actionSearch(){ return $this->render('search'); } public function actionSearchResult() { $model = new SearchModel(); if ($model->load(\Yii::$app->request->post())){ $booksIds = $model->search(); if (count($booksIds) == 1){ return $this->redirect(Url::to(['support/index', 'book_id' => $booksIds[0]])); }else{ $dataProvider = new ActiveDataProvider( [ 'query' => Book::find() ->with( [ 'author', 'alias', ] ) ->where([ 'status' => Book::STATUS_ACTIVE ])->andWhere(['book.id' => $booksIds]), 'pagination' => [ 'pageSize' => 10, ], ] ); return $this->render( 'search-result', [ 'dataProvider' => $dataProvider, ] ); } } } public function actionBuy($book_id = null){ $model = new Buy([ 'book_id' => $book_id, 'status' => 0 ]); $book = Book::find()->with('author')->where(['id' => $book_id])->one(); if ($model->load(\Yii::$app->request->post()) and $model->save()){ \Yii::$app->session->setFlash('success', 'Дякуємо за ваш запит. Найближчим часом, наш менеджер зв\'яжеться з Вами для уточнення деталей'); return $this->redirect(['site/index']); } return $this->render('buy', [ 'model' => $model, 'book' => $book ]); } }