Wed 7 Feb 2007
I try to do an RSS feed for every site I make and I realized the code is pretty much the same for each site, so I made it into a plugin. It’s pretty easy to use will work out of the box for most sites, I think. I also allowed for some configuration by editing the model that will be providing the data for the feed. Check out the full code and instructions for the CakePHP Automagic RSS Feed Plugin and let me know what you think!
Popularity: 14% [?]










Follow!
February 8th, 2007 at 3:39 am
Having the app controller named ChatAppController might cause you a few problems ;).
BTW why not use the rss stuff from 1.2
February 8th, 2007 at 10:09 am
Nice catch on the name thing - I obviously used my chat plugin as a base for this.
I wasn’t aware of the RssHelper support in Cake 1.2. I guess I should rename this “CakePHP Automagic RSS Plugin for Version 1.1″
March 1st, 2007 at 5:01 pm
Since I am using 1.1, I thought I would give this a bash, and everything works great except for the pubDate. right now it writes every date as Wed, 31 Dec 1969 18:00:00 +0100
March 1st, 2007 at 11:24 pm
Miggs,
What is the name of the the field you are using to store the date information? The plugin looks for the field “created” by default.
March 1st, 2007 at 11:45 pm
Matt, thanks for the response. Is there any way I can change which field it looks at? Or do I need to change my database field to be ‘created’?
March 2nd, 2007 at 10:02 am
Figured it out. Thanks for posting this solution. It is works great
March 2nd, 2007 at 11:29 am
Glad you got it working.
Definitely a mistake on my part to assume the created field should be mapped to pubDate. I can see scenarios where an article may be created, but not published until sometime later. I’ll issues an update to allow this field to be configured.
August 24th, 2007 at 4:14 am
Hello, thanks for this plugin. I would like to know how can i change the link for the view, “The link will be ‘/{$model}/view/{$model->primaryKey}’ by default.”. The url of my view look like http://www.mydomain.com/folder/view/my_url. Can you tell me how can i make the rss plugin work with this type of url ? Thanks for your response and excuse my poor english.
August 24th, 2007 at 11:58 pm
Check out step #6 on http://sandbox.siteamonth.com/demo/rss.
You can use the $feed property in your model to override the default url.
November 8th, 2007 at 7:12 am
Hello,
I used the plugin on cake 1.17. With debug mode on 2, you can see that the queries are send to the database. However, the feed does not return the retrieved records. The RSS header is retrieved, but none of the 6 records in the database are shown as items in the feed.
Any suggestions?
Kindr egards,
Martijn
Localhost Recent Contents
http://localhost
Thu, 08 Nov 2007 13:10:14 +0100
FeedCreator 1.7.2-ppt (info@mypapit.net)
9 queries took 39 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `contents`6618
2DESCRIBE `comments`6614
3SELECT `Content`.`id`, `Content`.`language`, `Content`.`section`, `Content`.`body`, `Content`.`layout`, `Content`.`view` FROM `contents` AS `Content` WHERE 1 = 1 ORDER BY `Content`.`id` DESC LIMIT 10661
4SELECT `Comment`.`id`, `Comment`.`author`, `Comment`.`email`, `Comment`.`posted`, `Comment`.`comment`, `Comment`.`content_id` FROM `comments` AS `Comment` WHERE `Comment`.`content_id` IN (6) ORDER BY `Comment`.`posted` DESC LIMIT 5001
5SELECT `Comment`.`id`, `Comment`.`author`, `Comment`.`email`, `Comment`.`posted`, `Comment`.`comment`, `Comment`.`content_id` FROM `comments` AS `Comment` WHERE `Comment`.`content_id` IN (5) ORDER BY `Comment`.`posted` DESC LIMIT 5001
6SELECT `Comment`.`id`, `Comment`.`author`, `Comment`.`email`, `Comment`.`posted`, `Comment`.`comment`, `Comment`.`content_id` FROM `comments` AS `Comment` WHERE `Comment`.`content_id` IN (4) ORDER BY `Comment`.`posted` DESC LIMIT 5331
7SELECT `Comment`.`id`, `Comment`.`author`, `Comment`.`email`, `Comment`.`posted`, `Comment`.`comment`, `Comment`.`content_id` FROM `comments` AS `Comment` WHERE `Comment`.`content_id` IN (3) ORDER BY `Comment`.`posted` DESC LIMIT 5551
8SELECT `Comment`.`id`, `Comment`.`author`, `Comment`.`email`, `Comment`.`posted`, `Comment`.`comment`, `Comment`.`content_id` FROM `comments` AS `Comment` WHERE `Comment`.`content_id` IN (2) ORDER BY `Comment`.`posted` DESC LIMIT 5001
9SELECT `Comment`.`id`, `Comment`.`author`, `Comment`.`email`, `Comment`.`posted`, `Comment`.`comment`, `Comment`.`content_id` FROM `comments` AS `Comment` WHERE `Comment`.`content_id` IN (1) ORDER BY `Comment`.`posted` DESC LIMIT 5001
November 8th, 2007 at 9:21 am
Hey Martijn,
Did you tell it which fields in your database map to the which fields in the RSS feed? It detects some automatically.
November 27th, 2007 at 10:09 pm
Every time my feed is generated, it’s generated with a single blank line at the top, invalidating the xml. How do I fix this?
November 27th, 2007 at 10:17 pm
fmic,
Which version of Cake are you using?
November 27th, 2007 at 10:22 pm
1.1
November 28th, 2007 at 9:12 am
Latest 1.1?
Are you using caching at all? I remember having some problem when caching was enabled.
November 28th, 2007 at 6:04 pm
I found out I had a blank space after the ?> in app_model.php that threw the extra space in. Thank god for grep.
You don’t really entail how to use custom links in step six- it doesn’t even say what %s stands for, or how I can access other information about the current record. Could you clarify?
Thanks.
November 28th, 2007 at 6:53 pm
fmic,
Glad you got your space problem fixed.
As for the link, %s is replaced with the primary key. Probably would have made more sense to use %d since most PKs are ids, but I guess I was leaving the door open using pretty urls.
I meant for this to be pretty basic and to be customized for a particular app. So feel free to adapt to fit your needs.
November 30th, 2007 at 5:09 pm
http://bin.cakephp.org/saved/25749
That’s the ‘improved’ version I wrote to allow more flexibility within each feed. Now the feed title, the created field (kept throwing errors at me), the link, and a few other things can be designated in the model.
For the link, I changed it to an associative array, where ‘url’ is the link to it, with [%value] substituted for the column you specify in ‘value’.
IE, if I wanted to use the post’s title, my array would be: array(’url’ => ‘/posts/view/[%value]/’, ‘value’ => ‘title’);