W3Counter 4.0: AJAX in Symfony is a Breeze

December 27 2 Comments Category: Development, W3Counter

I’ve gotta say, reproducing the AJAX effects from W3Counter within symfony was much easier than expected. It took only a few minutes to master and the code practically wrote itself.

W3Counter 12.27.2006

Using a pre-built framework for this project is saving me time all over the place and producing code I’m not ashamed to share. Several of the reports W3Counter provides have “drill down” features, including the web browser stats which I completed rewriting today. The browsers are listed grouped by the family (Firefox, Internet Explorer, etc). Each row can be expanded to “drill down” to the stats for particular versions of that browser family.

W3Counter right now uses about 40 lines of JavaScript to accomplish this effect, from initializing and sending the XMLHttpRequest to modifying various div contents and parsing the response.

Version 3 with Symfony required no extra coding at all. I simply filled out the parameters for Symfony’s link_to_remote() helper function in the template, and out comes a link which toggles the visibility of the table row, issues the XMLHttpRequest for the cell contents, fills it in when it comes back, and even runs a Script.aculo.us effect upon completion.

echo link_to_remote(image_tag('icons/magnifier_zoom_in.png', array('alt' => 'View By Version')),
array(
'url' => '@browser_drilldown' . $params,
'update' => array('success' => 'expand_cell_' . $i),
'complete' => "Element.show('expand_row_" . $i . "')"
));

The best part is that there was no extra coding required to write the code which responds to the request. It’s just a standard action within my module like any page of the application. Symfony automatically recognizes the request came from an XMLHttpRequest, and skips decorating the template with the layout before sending the response back to the page. Talk about easy.

One task remains… I almost forgot to handle the case when a user tries to expand a row after their session has timed out. You can see the default result below: Symfony redirects the request to my auth module which returns its login screen right into the middle of my page. I’ll fix that up tomorrow.

W3Counter 12.27.2006 Oops

2 Responses

Write a comment
  1. Hey Dan,
    Not totally relavent to this post, but I’m curious. From a privacy standpoint have you ever or are you concerned with W3Counter? I was listening to a lecture the other day in regards to the Pharmatrak lawsuit and I was curious what relavence this might have:

    http://www.infoworld.com/articles/hn/xml/00/08/22/000822hnpharma.html

    Robert Norton 28 December 2006 at 10:28 am Permalink
  2. Can’t say I’m very worried about that. I don’t see a judge ruling that you can’t analyze anonymous web access logs for general site access trends out of concern for medical privacy. If that happens, hopefully those sites will stop using web analytics services rather than those services somehow being to blame.

    Dan 28 December 2006 at 7:37 pm Permalink

Write a Comment

Commenter Gravatar