For deleting user information in cake php by clicking on delete button we have to first pass user id in URL by using below code in our view.
<?php echo $this->Html->link('Delete',array('action'=>'del'.$user['User']['id']));
And we have to put the following code in that function where we will wright code for deleting data in our controller.
public function delete($id) { // here we are getting $id from the url
if(isset($id) && !empty($id)){ // checking wheather we are getting id from url or not
$user = $this->Auth->User('id'); //finding user details by the id
if($id== $user){
$this->User->delete($id);
$this->redirect(array('action' => 'logout'));
}
$this->Session->setFlash('you cant delete this user');
$this->redirect(array('action' => 'display'));
}
else{
$this->redirect(array('action' => 'display'));
}
}
0 Comment(s)