Thursday, December 8th, 2005

Symfony “advent calendar” tutorial series

Category: Articles, PHP, Prototype

The PHP5 web framework Symfony has a “advent calendar” long tutorial series running. Each day will cover building a web application using Symfony, so its not all ajax-specific. However, day eight covers adding ajax functionality, so if you are just curious to see how easy ajax is with symfony, check that out.

The application used for an example is similiar to digg, where you can indicate your interest or disinterest in items with a click which updates instantly. Symfony uses the Prototype library underneath, so the following block of code will be familiar to Rails or Scriptaculous users:

return link_to_remote(‘interested?’, array(
‘url’ => ‘user/interested?id=’.$question->getId(),
‘update’ => array(‘success’ => ‘block_’.$question->getId()),
‘loading’ => “‘indicator’)”,
‘complete’ => “Element.hide(‘indicator’);”.visual_effect(‘highlight’, ‘mark_’.$question->getId()),));

It makes an ajax call to “user/interested” with your question id, showing the “indicator” element while loading and doing a highlight effect when completed. The “update” hash tells symfony what dom element to update on completion. Very nice and concise.

Posted by Rob Sanheim at 1:29 pm
Comment here

3.8 rating from 41 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.