The definitive guide of Symfony 1.2

Chapter 11. Ajax Integration

Interactions on the client side, complex visual effects, and asynchronous communication are common in Web 2.0 applications. All those require JavaScript, but coding it by hand is often cumbersome and time-consuming to debug. Fortunately, symfony automates many of the common uses of JavaScript in the templates with a complete set of helpers. Many of the client-side behaviors can even be coded without a single line of JavaScript. Developers only need to worry about the effect they want to achieve, and symfony will deal with complex syntax and compatibility issues.

This chapter describes the tools provided by symfony to facilitate client-side scripting:

  • Basic JavaScript helpers output standards-compliant <script> tags in symfony templates, to update a Document Object Model (DOM) element or trigger a script with a link.
  • Prototype is a JavaScript library integrated in symfony, which speeds up client-side scripting development by adding new functions and methods to the JavaScript core.
  • Ajax helpers allow the user to update some parts of a page by clicking a link, submitting a form, or modifying a form element.
  • The many options of these helpers provide even greater flexibility and power, notably by the use of callback functions.
  • Script.aculo.us is another JavaScript library, also integrated in symfony, which adds dynamic visual effects to enhance the interface and the user experience.
  • JavaScript Object Notation (JSON) is a standard used to communicate between a server and a client script.
  • Complex client-side interactions, combining all the aforementioned elements, are possible in symfony applications. Autocompletion, drag-and-drop, sortable lists, and editable text can all be implemented with a single line of PHP — a call to a symfony helper.