namespace App\Controller; use App\Controller\AppController; /** * Persons Controller * * @property \App\Model\Table\PersonsTable $Persons */ class PersonsController extends AppController { /** * Index method * * @return \Cake\Network\Response|null */ public function index() { $persons = $this->paginate($this->Persons); $this->set(compact('persons')); $this->set('_serialize', ['persons']); } /** * View method * * @param string|null $id Person id. * @return \Cake\Network\Response|null * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function view($id = null) { $person = $this->Persons->get($id, [ 'contain' => [] ]); $this->set('person', $person); $this->set('_serialize', ['person']); } /** * Add method * * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. */ public function add() { $person = $this->Persons->newEntity(); if ($this->request->is('post')) { $person = $this->Persons->patchEntity($person, $this->request->data); if ($this->Persons->save($person)) { $this->Flash->success(__('The person has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The person could not be saved. Please, try again.')); } } $this->set(compact('person')); $this->set('_serialize', ['person']); } /** * Edit method * * @param string|null $id Person id. * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $person = $this->Persons->get($id, [ 'contain' => [] ]); if ($this->request->is(['patch', 'post', 'put'])) { $person = $this->Persons->patchEntity($person, $this->request->data); if ($this->Persons->save($person)) { $this->Flash->success(__('The person has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The person could not be saved. Please, try again.')); } } $this->set(compact('person')); $this->set('_serialize', ['person']); } /** * Delete method * * @param string|null $id Person id. * @return \Cake\Network\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $person = $this->Persons->get($id); if ($this->Persons->delete($person)) { $this->Flash->success(__('The person has been deleted.')); } else { $this->Flash->error(__('The person could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); } } //ここから追加 public function edit($id = null) { $person = $this->Persons->get($id); if ($this->request->is(['post','put'])) { $person = $this->Persons->patchEntity($person, $this->request->data); if ($this->Persons->save($person)) { return $this->redirect(['action' => 'index']); } }else{ $this->set('person',$person); } } }
editが重複しているのはわかっていますが、順番通りにやると、どうしてもこうなってしまいます。
どうすればいいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/21 05:44
2016/02/21 05:52 編集
2016/02/21 06:44 編集
2016/02/21 07:29
2016/02/21 08:18