loadModel(); $tableAlias = $table->getAlias(); $this->set($tableAlias, $this->paginate($table)); $this->set('tableAlias', $tableAlias); $this->set('_serialize', [$tableAlias, 'tableAlias']); } /** * View method * * @param string|null $id User id. * @return void * @throws NotFoundException When record not found. */ public function view($id = null) { $table = $this->loadModel(); $tableAlias = $table->getAlias(); $entity = $table->get($id, [ 'contain' => [] ]); $this->set($tableAlias, $entity); $this->set('tableAlias', $tableAlias); $this->set('_serialize', [$tableAlias, 'tableAlias']); } /** * Add method * * @return mixed Redirects on successful add, renders view otherwise. */ public function add() { $table = $this->loadModel(); $tableAlias = $table->getAlias(); $entity = $table->newEntity(); $this->set($tableAlias, $entity); $this->set('tableAlias', $tableAlias); $this->set('_serialize', [$tableAlias, 'tableAlias']); if (!$this->request->is('post')) { return; } $entity = $table->patchEntity($entity, $this->request->getData()); $singular = Inflector::singularize(Inflector::humanize($tableAlias)); if ($table->save($entity)) { $this->Flash->success(__d('CakeDC/Users', 'The {0} has been saved', $singular)); return $this->redirect(['action' => 'index']); } $this->Flash->error(__d('CakeDC/Users', 'The {0} could not be saved', $singular)); } /** * Edit method * * @param string|null $id User id. * @return mixed Redirects on successful edit, renders view otherwise. * @throws NotFoundException When record not found. */ public function edit($id = null) { $table = $this->loadModel(); $tableAlias = $table->getAlias(); $entity = $table->get($id, [ 'contain' => [] ]); $this->set($tableAlias, $entity); $this->set('tableAlias', $tableAlias); $this->set('_serialize', [$tableAlias, 'tableAlias']); if (!$this->request->is(['patch', 'post', 'put'])) { return; } $entity = $table->patchEntity($entity, $this->request->getData()); $singular = Inflector::singularize(Inflector::humanize($tableAlias)); if ($table->save($entity)) { $this->Flash->success(__d('CakeDC/Users', 'The {0} has been saved', $singular)); return $this->redirect(['action' => 'index']); } $this->Flash->error(__d('CakeDC/Users', 'The {0} could not be saved', $singular)); } /** * Delete method * * @param string|null $id User id. * @return Response Redirects to index. * @throws NotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $table = $this->loadModel(); $tableAlias = $table->getAlias(); $entity = $table->get($id, [ 'contain' => [] ]); $singular = Inflector::singularize(Inflector::humanize($tableAlias)); if ($table->delete($entity)) { $this->Flash->success(__d('CakeDC/Users', 'The {0} has been deleted', $singular)); } else { $this->Flash->error(__d('CakeDC/Users', 'The {0} could not be deleted', $singular)); } return $this->redirect(['action' => 'index']); } }