Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to delete user by using cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 670
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: