×

Sign in with twitter.

You can follow the user and hashtags.

Share your tips on social media.

Post relative tips.

If you have relative tips, click [Add relative tips] to post.

Deleteメソッドへのリンクは「$this->Form->postLink()」で処理する [CakePHP2.1]

@takahashiyuya@takahashiyuya 3909 viewer 58 embed viewer embed
「$this->Form->postLink()」というメソッドは「$this->Html->link()」と使い方は同じですが、postで送信するという役割があるので、セキュアなアクションで有用かと思われます。

ーーーー
・ビュー

<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $blog['Blog']['id']), null, __('Are you sure you want to delete # %s?', $blog['Blog']['id'])); ?>


・コントローラ

public function delete($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->Blog->id = $id;
if (!$this->Blog->exists()) {
throw new NotFoundException(__('Invalid blog'));
}
if ($this->Blog->delete()) {
$this->Session->setFlash(__('Blog deleted'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Blog was not deleted'));
$this->redirect(array('action' => 'index'));
}


#cakephp2.1

Click this to change format.

Add relative tips

Users who share this tip.

Comments