protected function findModel($id)
 {
     if (($model = Chapter::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
 public function search($params)
 {
     $query = Chapter::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!$this->load($params)) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'book_id' => $this->book_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
示例#3
0
 public function actionIndex()
 {
     $books = Book::find()->all();
     $data = array();
     foreach ($books as $book) {
         $dataBook = array();
         $dataBook['label'] = substr($book->name, 0, strpos($book->name, ':'));
         $listChapter = Chapter::find()->where(['book_id' => $book->id])->all();
         $dataBook['content'] = $this->renderPartial('list', ['book' => $book, 'listChapter' => $listChapter]);
         $data[] = $dataBook;
     }
     return $this->render('index', ['data' => $data]);
 }