こんばんは。
トクハラです。
いま、いろんな人に謝りたい。
色々とすみません。
ということで(どういうことだ?)、cakephpネタ。
cakephpでUPDATEすると、$this->request->dataの中には更新したものしか入ってません。
これが、非常に困ることがある。
例えば、バリデーションでエラーにしたときなど、急にindexがありませんとかで怒られる。
ということで、saveに失敗したときにはcontroller側で強引に詰め直すことにした。
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->sample->save($this->request->data)) {
$this->Session->setFlash(__('The sample has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The sample could not be saved. Please, try again.')); //ここでもう一度データを取り直す $results = $this->sample->read(null, $id); //詰め直す $this->request->data['sample']['hoge_id'] = $results['sample']['hoge_id']; }
・・・・これはバッドノウハウの気がする。
誰か偉い人、良い解決方法があれば教えてください。