CakePHP and AJAX: First pitstop
April 11th, 2007 | Published in AJAX | 1 Comment
I started out with the Cake framework for PHP some time back, and it’s been a mixed ride so far. Cake is a very powerful, but still somewhat incipient framework built on the MVC pattern of Ruby on Rails. Among it’s several cool features is inbuilt support for AJAX based applications.
A good starter tutorial in that direction lies here. And another one, a Flickr Gallery.
However, if you belong to the population of web developers who are not psychic or lucky, you would probably have something like this staring your face when you try the above tutorials -
Fatal error: Call to a member function on a non-object in C:\cake\app\views\layouts\default.thtml on line 8
That’s because both the tutorials do not explicitly mention that you need to declare the AJAX helper in the controller file if you are going to use AJAX features. The best way to do that is to copy the app_controller.php file from your cake/ directory, put it in your app/ directory and add the following piece of code to it:
var $helpers = array('Html', 'Ajax', 'Javascript');This declares the Helpers in the parent class of all the controllers, so that you don’t need to re-declare them later. If you do that, though, make sure to have all the helpers declared again.

April 29th, 2007 at 9:53 pm (#)
If someone could provide a good AJAX login tutorial with CakePHP, that would be awesome.