The Blogs Page: The AJAX feed digest view helper
Sunday, April 4, 2010
The implementation of the AjaxFeedDigest view helper is contained in the file AjaxFeedDigest.php, which is located in the /application/views/helpers directory.
The class is named Default_View_Helper_AjaxFeedDigest. Note that
- The prefix used is that declared in the application.ini file
- The location of the implementation file is also as declared there
- The name of the file is the name of the class without the prefix
The class is implemented as follows:
class Default_View_Helper_AjaxFeedDigest extends Zend_View_Helper_Abstract { public function ajaxFeedDigest($id) { $divId = sprintf('blog_%s', $id); $script = sprintf('$(document).ready(function() { $("#%s").load("/feed/digest/id/%s"); });', $divId, $id); $html = sprintf('<div id="%s"></div>' . PHP_EOL, $divId) . $this->view->inlineScript()->setScript($script); return $html; } }
The class renders two blocks of HTML:
- A container for the information returned by the AJAX request
- A script used to make the AJAX request
The container is given a unique ID, based on the ID of the blog from the database. This is to allow the request to be made for mutliple blogs.
The script makes use of the standard jQuery call $(document).ready(…) to pass a function which needs to be executed when the document has been loaded fully. This function makes the AJAX request for the blog digest, and the response is displayed in the container.


