With Garden, turning any view into a syndication view is a breeze.
Creating a syndication feed is just as easy as creating a normal web page. For example, let's say I wanted to create a feed for all of the discussions in Vanilla. I could add a "feed" method to my DiscussionsController class in Vanilla. Within that method I would change the master view to whatever syndication format I want to use (Garden provides RSS2 and Atom master views by default), I'd load the appropriate data using my Discussion Model, and then I'd create a view for my feed method which looped the records, writing out each item.
That's pretty easy, but it seems silly to create a custom method for loading data that already has a method created to do the same thing. For example, the DiscussionsController I just mentioned already has an "Index" method that loads all of the latest discussions and displays them as xhtml. All I really need to do is create a custom view for the rendering of the feed items and use the data loaded by that method. Garden let's you do that easily with...
You can turn any url in Garden into a syndication url by prefixing the route with "rss" or "atom". Garden will then know to (a) select the appropriate master view for that syndication type, and (b) select an alternate rss or atom version of the view file. So, if I were to change the url to Vanilla's discussions on my local dev server:
http://localhost/garden/discussions
to
http://localhost/garden/discussions/feed.rss
Garden would select the rss master view, and instead of selecting the default view (index.php), it would look for an index_rss.php view in the same view folder.
So, all I would have to do in order to turn any page in Garden into a syndicated page, is to create an alternate view for the data with the appropriate syndication method as a view filename suffix (ie. viewfilename_atom.php or viewfilename_rss.php).
What if the feed you are serving changes rarely? It doesn't make sense to waste unnecessary bandwidth and CPU cycles on delivering data that hasn't changed. Garden takes care of this with HTTP's conditional GET mechanism. The controller base class has a SetLastModified($Date) method that allows you to specify the last date that this particular feed (or page, for that matter) was modified. Clients will then send this information back to Garden when they are requesting data, and Garden will know to either (a) deliver the new data, or (b) tell the client that there have been no changes and send nothing back.
| Edited September 2010 by Tim |