Using Zend_Feed
Zend_Feed is a small component of the Zend Framework that encapsulates all of the complexities of creating web feeds behind a simple, easy-to-use interface. It will help us get a working, tested, RSS compliant data feed in place in very little time. All we will need to do is format our comment data in a manner expected by Zend_Feed, and it does the rest.
We need a place to house the code to handle the requests for our feed. We could create a new controller for this, but to keep things simple, we'll just add a new action method to our main CommentController.php file to handle the requests. Rather than add to the method a little at a time, we'll list the entire method here, and then talk through what it is doing.
Open up CommentController.php and add the following public method:
public function actionFeed()
{
if(isset($_GET['pid'])) $projectId = intval($_GET['pid']);
else $projectId = null;
$comments = Comment::model()->findRecentComments(20, $projectId);
//convert from...