Overview
KB
Learn PHP
PHP techniques
PHP Smarty Functions
PHP Web Email
Secure development
PHP Security Scenario
SSH and SFTP
PHP Smarty
PHP Smarty Modifiers
PHP Smarty Caching
PHP Smarty Misc
CakePHP
Zend Framework
PHP basics

CakePHP Development

How to debug Ajax calls?

While we were working on this tutorial, all of a sudden we learned that some of the work was done for us by nice folks at php-editors.com. They published two new articles, where they covered the use of PHP IDE in the development of Web 2.0 applications with PHP on the back end: Even though neither article is related to CakePHP, "Debugging PHP, JSON and JavaScripts Application using PHP IDE" covers the use of DebugBreak() function to intercept the JavaScript injection requests to PHP scripts on the server. In summary, this is very simple:

You can place the call to the function DebugBreak() provided by dbg debugger in any place of CakePHP files (PHP or view .thtml) and the moment this function is hit, PhpED will automatically start the debug session.

Lets do it really quickly, first enable the Ajax link:
  • Place prototype.js file in app/webroot/js folder - you can get it from www.prototypejs.org
  • To invoke Ajax helper add
    var $helpers = array('Html', 'Javascript', 'Ajax');
    to posts_controller.php in PostsController class
  • Change index.thtml:
    • Add javascript links:
      <?php print $html->charsetTag('UTF-8'); 
      print $javascript-link('prototype');?>
    • Replace
      <?php echo $html->link( 
          'Delete', 
          "/posts/delete/{$post['Post']['id']}", 
          null, 
          'Are you sure?' 
      );
      With ajax link version:
      <?php echo $ajax->link( 
          'Delete', 
          "/posts/delete/{$post['Post']['id']}", 
          null, 
          'Are you sure?' 
      );
    Your code is now Ajax enabled and delete post action link will actually result in Ajax call to the controller. If you place DebugBreak() in delete() method of PostsController class, you will see how Ajax debugging works:
  • Run index.php in external browser to avoid the deadlock:
CakePHP PHP Ajax files

  • Click on delete now and see debugging session start:
CakePHP PHP Ajax Debugging

And that's the icing on top of CakePHP!

Please check again soon and make sure you subscribe to NuSphere News Letter to learn about new PHP Tools available in PhpED. Additional technical information is available from the NuSphere Support Forum. Download a free trial of PHP IDE for PHP Frameworks today!

Article continues:  <<previous page

 Download NuSphere PHP IDE

Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.

 Buy NuSphere PhpED® now

Best PHP Editor and complete PHP IDE.
NuSphere PhpED 18.0 is available from our online store front.

 Special Team4 Offer

Get 4 copies of PhpED for the price of 3!

Optimum solution for development teams.
PhpED 18.0 Team4
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward,
Director of Technology
caboodal.com