Troubleshooting is tracking down pesky bugs, rooting them from the code and squashing them. Having some basic troubleshooting skills can greatly enhance your bug fighting. The goal of troubleshooting is to quickly identify the root cause of the problem, however, don’t confuse troubleshooting with problem solving. Problem solving is answering the question, “Can this be [...]
Using QuickCursor to edit in your favorite editor.
by bestep on 24. Apr, 2010 in Programming, Technology, Writing
QuickCursor from HogBaySoftware allows the use of your favorite text editor from any application. For me, that means I can hit a short key command, and open TextMate to edit blog posts, email replies, twitter messages, anything my heart desires, even Scrivener scenes/documents. It works with a variety of editors, including TextMate, WriteRoom, BBEdit, and [...]
RSS feed in Zend Framework
by bestep on 26. May, 2008 in Featured, Programming
Going to get a little geeky here. But I wanted to share a simple, and effective way to create a simple rss feed of content in the Zend Framework.
The new ClubReading site is separated into two parts, the blog, and the books. The books site is now using Disqus for the comments, and so far Disqus is working out great, but that’s a topic for another day. The blog is a wordpress blog. What I wanted to do was display a couple or three of the recently added books from the books site on the sidebar of the ClubReading Blog. My thought was to create a simple rss feed of the most recent books, and use the standard wordpress rss widget to display the feed content in the sidebar. But – how to create the rss feed? Turns out it was pretty simple thanks to a great article by Alex Netkachov called “Syndicate content with Zend Framework Zend_Feed classes”.
What is an RSS feed?
Simply put, RSS, Really Simple Syndication, is a file format. Think of it as a form letter. Like a business letter, because the format is standardized, the reader knows where to find the from address, to address, salutation, content…and so on. An RSS feed does the same thing by taking content and making it available in a standardized format.
What does an RSS feed look like?
RSS feeds are in xml format. XML, or the Extensible Markup Language, presents any type of information within descriptive tags. Tags are closed in <> and can be anything. Don’t confuse the xml tags with html. For example, in html to bold a bit of text, just enclose the text in the <b> tag, for example, <b>Bold</b> is in bold would show in the browser as Bold is in bold. XML tags work the same way, they open and close. So we might have a description tag like this:
<description> Description text </description>
There are several types or standards of RSS feeds. A great place to start is the RSS 2.0 Specification article at Harvard Law. As the article states,
RSS is a dialect of XML. All RSS files must conform to the XML 1.0 specification, as published on the World Wide Web Consortium (W3C) website.
RSS feeds basically consist of a header section that describes the feed, and a repeating section for items or content. So, the first thing I did was create a sample RSS file to work with as a template. I want to feed to show the Book Title, Author and who entered the book. Here’s the sample I came up with:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title>ClubReading Books></title>
<link>http://books.clubreading.com/index/rss</link>
<description>An online community for the avid book lover.></description>
<pubDate>Mon, 26 May 2008 21:28:50 +0000</pubDate>
<generator>Zend Framework Zend_Feed</generator>
<language>en-us</language>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>Clans of the Alphane Moon></title>
<link>http://books.clubreading.com/book/bookdetail/book_id/2582</link>
<guid>http://books.clubreading.com/book/bookdetail/book_id/2582</guid>
<description>by: Philip K. Dick, entered by: Bill Estep></description>
<pubDate>Mon, 26 May 2008 21:28:50 +0000</pubDate>
</item>
</channel>
</rss>
As you can see, the document opens with the <channel> tag and some information about the feed. Then the items repeat in the <item> tag. For my sample document, I only used one item for simplicity.
Creating the RSS feed
The next decision to make was where to put the rss feed code? I made the decision to access the recent books feed from the index controller, so the final url will look like http://books.clubreading.com/index/rss. So, I created a created an empty view field rss.phtml in the application/views/scripts/index folder.
Next, in the IndexController, I added an rssAction function. To keep things simple, all the function needs to do is get a list of recently added books, format the feed data into an array, then dump the feed. Following Alex’s example, here’s what the final action looks like:
function rssAction()
{
// get recent books
$books = Book::recentbooks(3,0);
$baseUrl = 'http://books.clubreading.com';
$tempbook = $books->current();
$pubDate = $tempbook->date_entered;
$feedArray = array(
'title' => 'ClubReading Books',
'link' => 'http://books.clubreading.com/index/rss',
'description' => 'An online community for the avid book lover.',
'language' => 'en-us',
'charset' => 'utf-8',
'pubDate' => $pubDate,
'generator' => 'Zend Framework Zend_Feed',
'entries' => array()
);
foreach ($books as $book) {
$feedArray['entries'][] = array(
'title' => $book->book_title,
'link' => $baseUrl . '/book/bookdetail/book_id/' . $book->book_id,
'guid' => $baseUrl . '/book/bookdetail/book_id/' . $book->book_id,
'description' => 'by: ' . $book->author . ', entered by: ' . $book->entered_by,
'pubDate' => $book->date_entered
);
}
$feed = Zend_Feed::importArray($feedArray, 'rss');
// Not needed - see comments
foreach ($feed as $entry) {
$element = $entry->summary->getDOM();
}
$feed->send();
}
The Result
Well, the new rssAction works like a champ! All that remained was to add the RSS widget to the wordpress sidebar and give it the url to the new rss feed.

I also added a subscribe icon to the Recent Books section of the Books website. After a quick google search, I found Feed Icons, and downloaded the publicly available Mozilla feed icons.
Like most programming adventures, there are as many different ways to implement a solution as there are programmers.
I don’t profess to implement any best practice…or even good code. But this worked for me, and maybe others will find it useful. Overall, a fun learning experience.
-
RSS feed in Zend Framework
26. May, 2008
-
ClubReading Facelift
24. May, 2008
-
Authors Play Waldo
01. Mar, 2009
-
Roll Your Characters
01. Jun, 2010
-
Taylor Hicks – Home Run!
09. Apr, 2009
-
Roger Update
28. Jul, 2010
-
Work In Progress
26. Jul, 2010
-
Very Cool!
24. Jul, 2010
-
Naming Things
22. Jul, 2010
-
Evernote Again
20. Jul, 2010
-
Sally Pratt: Looking good!! Thanks for the link on African Vio...
-
Linda: Very cool. Please keep us updated. And please pu...
-
bestep: Yes, he's turned frequently. The growth looks even...
-
Sally Pratt: Are you turning it weekly? It looks very healthy....
-
bestep: lol - well...it doesn't look like he spends a lot ...
Tweets
Photos on flickr
Archives
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008







