top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to delete a record using POST method in CakePHP?

0 votes
71 views
How to delete a record using POST method in CakePHP?
posted Jul 31, 2014 by Mohit Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can use postLink method of FormHelper .

In view file ,you should use:

echo $this->Form->postLink('Delete',
array('action' => 'delete', $list['Memberlist']['id']),
array('class'=>'btn-mini btn', 'confirm' => 'Are you sure?'));

In the Controller,use following code:
public function delete($id) {
if($this->request->is('get')) {
throw new MethodNotAllowedException();
}

$this->Memberlist->id = $id;
if (!$this->Memberlist->exists()) {
    throw new NotFoundException(__('Invalid list.'));
}
if ($this->Memberlist->delete()) {
    $this->Session->setFlash(__('List deleted.'), 'success');
    return $this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('List was not deleted.'), 'error');
return $this->redirect(array('action'=>'index'));

}

answer Aug 1, 2014 by Rahul Mahajan
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...