/** * index method * * @return void */ public function index() { $this->->recursive = 0; $this->set('', $this->Paginator->paginate()); } /** * view method * * @throws NotFoundException * @param string $id * @return void */ public function view($id = null) { if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } $options = array('conditions' => array('.' . $this->->primaryKey => $id)); $this->set('', $this->->find('first', $options)); } /** * add method * * @return void */ public function add() { if ($this->request->is('post')) { $this->->create(); if ($this->->save($this->request->data)) { $this->Session->setFlash(__('The has been saved')); return $this->redirect(array('action' => 'index')); return $this->flash(__(' saved.'), array('action' => 'index')); } $this->Session->setFlash(__('The could not be saved. Please, try again.')); } {$assoc} as $associationName => $relation): if (!empty($associationName)): $otherModelName = $this->_modelName($associationName); $otherPluralName = $this->_pluralName($associationName); echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n"; $compact[] = "'{$otherPluralName}'"; endif; endforeach; endforeach; if (!empty($compact)): echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n"; endif; ?> } /** * edit method * * @throws NotFoundException * @param string $id * @return void */ public function edit($id = null) { if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } if ($this->request->is('post') || $this->request->is('put')) { if ($this->->save($this->request->data)) { $this->Session->setFlash(__('The has been saved')); return $this->redirect(array('action' => 'index')); return $this->flash(__('The has been saved.'), array('action' => 'index')); } $this->Session->setFlash(__('The could not be saved. Please, try again.')); } else { $options = array('conditions' => array('.' . $this->->primaryKey => $id)); $this->request->data = $this->->find('first', $options); } {$assoc} as $associationName => $relation): if (!empty($associationName)): $otherModelName = $this->_modelName($associationName); $otherPluralName = $this->_pluralName($associationName); echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n"; $compact[] = "'{$otherPluralName}'"; endif; endforeach; endforeach; if (!empty($compact)): echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n"; endif; ?> } /** * delete method * * @throws NotFoundException * @param string $id * @return void */ public function delete($id = null) { $this->->id = $id; if (!$this->->exists()) { throw new NotFoundException(__('Invalid ')); } $this->request->onlyAllow('post', 'delete'); if ($this->->delete()) { $this->Session->setFlash(__(' deleted')); return $this->redirect(array('action' => 'index')); return $this->flash(__(' deleted'), array('action' => 'index')); } $this->Session->setFlash(__(' was not deleted')); return $this->flash(__(' was not deleted'), array('action' => 'index')); return $this->redirect(array('action' => 'index')); }