25 October, 2008
Tonight has been a bit of an interesting discovery session for myself. My experience level with CakePHP is growing fairly rapidly, and tonight I felt a genuine urge to change one of the Cookbook articles discussing RSS Feed Generation.
Its going on the list... Not the normal list.. But the real, fair-dinkum, life-goal list.
The article in question goes through some steps to produce a custom layout for RSS feeds and for the generation of channel and item content in accordance with the RSS 2.0 Specification. The article is well written, and achieves the purpose. I cannot fault it there. My issue is that it discusses the layout generation and the use of callback functions for rendering RSS items.
For starters, there is a perfectly good and well structured RSS layout already included with the CakePHP framework. This is included to try and reduce your required work. Its a simple matter of setting the right variables and passing those in the Cake-centric array style.
My second issue is with a the CakePHP RSSHelper itself, in that a callback function is used for the generation of individual RSS Items. This somewhat detracts from the general non-obtrusive manner in which CakePHP is structured. This is done with the $rss->items() function call. Not only is this out of the ordinary, but inside the view you are being asked to define a function, and once you enter that function, you no longer have access to helpers that may have been assigned at the controller level.
I don't know when it happened, but somewhere along the line, it was decided that a traditional for loop needed to be abstracted.
My suggestion to anyone out there trying to get their data represented in an RSS format, is to use a standard for loop over the data that is already assigned to the view, and echo $rss->item() on the array of required attributes.
In any case, today marks the completion of some pretty neat integration of the blog post RSS Feed into the new site. Subscribe to receive updates as posts are made!
Tomorrow I should be able to complete the blog comments RSS feed, as well as finally adding in the Blog Post Syntax Highlighter so I can demonstrate some of this, instead of just talking about it.