Пример #1
0
 /**
  * Updates an existing Author model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->author_id]);
     } else {
         $searchModel = new \app\models\BookSearch();
         $searchModel->author_id = $id;
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         return $this->render('update', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     }
 }
Пример #2
0
 /**
  * Displays a single Library model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $books = $model->books;
     $book_ids = [];
     foreach ($books as $book) {
         $book_ids[] = $book->book_id;
     }
     $searchModel = new \app\models\BookSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->query->andFilterWhere(['book_id' => $book_ids]);
     $book = new \app\models\Book();
     if ($book->load(Yii::$app->request->post())) {
         if ($model->insertBook($book)) {
             $this->refresh();
             //                $book = new \app\models\Book();
         }
     }
     return $this->render('view', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'book' => $book]);
 }