7.1 AJAX
The AjaxHelper utilizes the ever-popular Prototype and script.aculo.us libraries for Ajax operations and client side effects. To use the AjaxHelper, you must have a current version of the JavaScript libraries from www.prototypejs.org and http://script.aculo.us placed in /app/webroot/js/. In addition, you must include the Prototype and script.aculo.us JavaScript libraries in any layouts or views that require AjaxHelper functionality.
You'll need to include the Ajax and Javascript helpers in your controller:
class WidgetsController extends AppController {
var $name = 'Widgets';
var $helpers = array('Html','Ajax','Javascript');
}
class WidgetsController extends AppController {var $name = 'Widgets';var $helpers = array('Html','Ajax','Javascript');}
Once you have the javascript helper included in your controller, you can use the javascript helper link() method to include Prototype and Scriptaculous:
echo $javascript->link('prototype');
echo $javascript->link('scriptaculous');
echo $javascript->link('prototype');echo $javascript->link('scriptaculous');
Now you can use the Ajax helper in your view:
$ajax->whatever();
$ajax->whatever();
If the RequestHandler Component is included in the controller then CakePHP will automatically apply the Ajax layout when an action is requested via AJAX
class WidgetsController extends AppController {
var $name = 'Widgets';
var $helpers = array('Html','Ajax','Javascript');
var $components = array( 'RequestHandler' );
}
class WidgetsController extends AppController {var $name = 'Widgets';var $helpers = array('Html','Ajax','Javascript');var $components = array( 'RequestHandler' );}
