<?= $this->Form->postLink(__('Delete'),
['action' => 'delete', $message->id],
['confirm' => __(○○, $message->id)]) ?>
<form name="post_xxx" style="display:none;"
method="post" action="/messages/delete/1">
<input type="hidden" name="_method" value="POST"/>
</form>
<a href="#" onclick="if (confirm(○○)) { document.post_xxx.submit(); }
event.returnValue = false;
return false;">Delete</a>
$message = $this->Messages->get($id);まず、Messagesの「get」を使って指定したIDのMessagesインスタンスを取得し、「delete」メソッドを使ってこれを削除する、というものですね。これで削除の処理が完成しました。
if ($this->Messages->delete($message))……
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $message = $this->Messages->get($id); if ($this->Messages->delete($message)) { $this->Flash->success(__('The message has been deleted.')); } else { $this->Flash->error(__('The message could not be deleted. Please, try again.')); } return $this->redirect(['action' => 'index']); }
<< 前へ |