Confirm before Deleting post in CakePHP

In the controller, create a delete function:

<?php
class EmployeeController extends AppController
{
public function delete($id)
{
$this->Employee->delete($id);
$this->Session->setFlash(‘The Employee is deleted.’);
$this->redirect(array(‘action’=>’index’));
}
}

In the view page, write the following code:

<a href=”#” onclick=”return confirm(‘Are you sure you want to delete this Employee?’);”>Delete</a>

Leave a Reply