CakePHP and jQuery - Unobtrusive actions

Posted by fortysixandtwo on Stack Overflow See other posts from Stack Overflow or by fortysixandtwo
Published on 2010-03-24T19:56:56Z Indexed on 2010/03/25 20:33 UTC
Read the original article Hit count: 324

Filed under:
|
|
|

I'm trying to make an unobtrusive action for deleting bookmarks in CakePHP. Allthough it's working just fine, I suspect there must be a better way to do this. Could someone please point me in the right direction?

function delete($id = null) {
  $ok = $this->Bookmark->delete($id);

  if($this->RequestHandler->isAjax()) {
    $this->autoRender = false;
    $this->autoLayout = false;
    $response = array('status' => 0, 'message' => 'Could not delete bookmark');

    if($ok) {
        $response = array('status' => 1, 'message' => 'Bookmark deleted');
    }

    $this->header('Content-Type: application/json');
    echo json_encode($response);
    exit();
  }
  // Request isn't AJAX, redirect.
  $this->redirect(array('action' => 'index'));
}

© Stack Overflow or respective owner

Related posts about cakephp

Related posts about AJAX