# Pastebin QsV0ywdZ paginate = [ 'contain' => ['Formats', 'Editorials', 'Collections', 'EditionPlaces', 'EditionCountries', 'LendingStates', 'CatalogueStates'] ]; $books = $this->paginate($this->Books); $this->set(compact('books')); } /** * View method * * @param string|null $id Book id. * @return \Cake\Http\Response|void * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function view($id = null) { $book = $this->Books->get($id, [ 'contain' => ['Formats', 'Editorials', 'Collections', 'EditionPlaces', 'EditionCountries', 'LendingStates', 'CatalogueStates', 'Authorities', 'Subjects', 'Texttypes', 'BooksLevels', 'Items', 'Lendings'] ]); $this->set('book', $book); } /** * Add method * * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. */ public function add() { $book = $this->Books->newEntity(); if ($this->request->is('post')) { $book = $this->Books->patchEntity($book, $this->request->getData()); if ($this->Books->save($book)) { $this->Flash->success(__('The book has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The book could not be saved. Please, try again.')); } $formats = $this->Books->Formats->find('list', ['limit' => 200]); $editorials = $this->Books->Editorials->find('list', ['limit' => 200]); $collections = $this->Books->Collections->find('list', ['limit' => 200]); $editionPlaces = $this->Books->EditionPlaces->find('list', ['limit' => 200]); $editionCountries = $this->Books->EditionCountries->find('list', ['limit' => 200]); $lendingStates = $this->Books->LendingStates->find('list', ['limit' => 200]); $catalogueStates = $this->Books->CatalogueStates->find('list', ['limit' => 200]); $authorities = $this->Books->Authorities->find('list', ['limit' => 200]); $subjects = $this->Books->Subjects->find('list', ['limit' => 200]); $texttypes = $this->Books->Texttypes->find('list', ['limit' => 200]); $this->set(compact('book', 'formats', 'editorials', 'collections', 'editionPlaces', 'editionCountries', 'lendingStates', 'catalogueStates', 'authorities', 'subjects', 'texttypes')); } /** * Edit method * * @param string|null $id Book id. * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $book = $this->Books->get($id, [ 'contain' => ['Authorities', 'Subjects', 'Texttypes'] ]); if ($this->request->is(['patch', 'post', 'put'])) { $book = $this->Books->patchEntity($book, $this->request->getData()); if ($this->Books->save($book)) { $this->Flash->success(__('The book has been saved.')); return $this->redirect(['action' => 'index']); } $this->Flash->error(__('The book could not be saved. Please, try again.')); } $formats = $this->Books->Formats->find('list', ['limit' => 200]); $editorials = $this->Books->Editorials->find('list', ['limit' => 200]); $collections = $this->Books->Collections->find('list', ['limit' => 200]); $editionPlaces = $this->Books->EditionPlaces->find('list', ['limit' => 200]); $editionCountries = $this->Books->EditionCountries->find('list', ['limit' => 200]); $lendingStates = $this->Books->LendingStates->find('list', ['limit' => 200]); $catalogueStates = $this->Books->CatalogueStates->find('list', ['limit' => 200]); $authorities = $this->Books->Authorities->find('list', ['limit' => 200]); $subjects = $this->Books->Subjects->find('list', ['limit' => 200]); $texttypes = $this->Books->Texttypes->find('list', ['limit' => 200]); $this->set(compact('book', 'formats', 'editorials', 'collections', 'editionPlaces', 'editionCountries', 'lendingStates', 'catalogueStates', 'authorities', 'subjects', 'texttypes')); } /** * Delete method * * @param string|null $id Book id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $book = $this->Books->get($id); if ($this->Books->delete($book)) { $this->Flash->success(__('The book has been deleted.')); } else { $this->Flash->error(__('The book could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); } }