したがって、1 つのモデルのインデックスには、関連するモデルのリストがあります。リストには、ポストリンクの削除を含めます。
ただし、別のモデルに属しているビューで削除ポストリンクを使用して 1 つのモデルを削除すると、CSRF エラーがスローされるようです。
これは Cake のセキュリティ コンポーネントが機能する方法かもしれませんが、これを回避する方法はありますか (セキュリティ対策を損なうことなく)。
編集:コードを追加します。
ビュー (この場合、私のエクササイズ モデルのインデックス ビュー) にリンクを投稿します。
echo $this->Form->postLink('Delete', array('controller' => 'folders', 'action' => 'delete', $key), array('class' => 'delete', 'confirm' => 'Are you sure? This will also delete all associated exercises.'));
フォルダー コントローラーの削除アクション:
public function delete($id) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->Folder->delete()) {
$this->Session->setFlash('Folder '.$id.' has been deleted.', 'default', array('class' => 'success'));
$this->redirect(array('controller' => 'exercises', 'action' => 'index'));
}
}