コード例 #1
0
 /**
  * Un-friends a user
  *
  * @return string
  */
 public function deleteUnfriend()
 {
     try {
         //User must be logged in
         if (!$this->auth->check()) {
             //Notify error
             $this->keeper->put('notificationError', 'You must log in to continue');
             //Return to login
             redirect('/login', 'location');
         }
         //Set validation rules
         $this->form_validation->set_rules('user_id', 'User identifier', 'required|xss_clean');
         //Validation fails
         if ($this->form_validation->run() === false) {
             //Raise exception
             throw new Exception('User identifier missing', 422);
         }
         //Un-friends them
         $results = $this->userRepo->unfriendUsers($this->auth->user(), $this->userRepo->findUser($this->input->post('user_id')));
         //Return results
         echo json_encode(['error' => !$results]);
     } catch (Exception $e) {
         //Unexpected error
         echo json_encode(['error' => true, 'message' => $e->getMessage()]);
     }
 }