CakePHPのフォームヘルパーを使っている時に、フォーム名を変えただけでエラーになることありますか?
CakePHPのバージョンは4です。
DBにPeopleという名前のテーブルを用意して、既存レコードを消去する実装をしています。
Peopleコントローラのdelete() -> deleteビューテンプレート-> Peopleコントローラのdestroy()の流れです。
PeopleController.phpの一部
・・・
public function delete(){
$id = $this->request->getQuery('id');
$entity = $this->People->get($id);
$this->set('entity',$entity);
}
public function destroy(){
if($this->request->is('Post')){
$data = $this->request->getData('Form3');
$entity = $this->People->get($data['id']);
$this->People->delete($entity);
}
return $this->redirect(['action'=>'index']);
}
・・・
ビューテンプレートdelete.php (v3以前では .ctpファイル)
<p>以下のレコードを削除しますか</p>
<div>id:<?= $entity['id']?></div>
<div>name:<?= $entity['name']?></div>
<div>mail:<?= $entity['mail']?></div>
<div>age:<?= $entity['age']?></div>
<hr />
<?= $this->Form->create($entity,['type'=>'post','url'=>['controller'=>'People',
'action'=>'destroy']]) ?>
<?= $this->Form->hidden('Form3.id')?>
<div><?=$this->Form->submit('削除') ?></div>
<?= $this->Form->end() ?>
このコードのForm3の部分(Controllerの中ほどに1つ、delete.phpの下から3行目に1つ)をPeopleに替えれば動くのですが、Peopleはテーブル名と被っていてわかりずらいかと思って、変えたらエラーが出て動作しなくなりました。Peopleに戻せば動作します。
エラーが出るのは、[削除]ボタンを押した後に以下のようなのが出ます。
Record not found in table "people"
回答よろしくお願いいたします。
足りない情報がありましたらご指摘お願いいたします。