Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

RSS feed on DataObjects


Reply

8 Posts   2109 Views

Avatar
cliersch

25 March 2009 at 6:01am Community Member, 75 Posts

Hi! The tutorial shows how to use the RSSFeed for Children of the site. I would like to have DataObjects as an RSS Feed. My Problem is, the RSSFeed needs to have a LINK but I'm not able to use $this->Link() for Objects. How can I a implement a Link method for my DataObjects to use the feed?

   function init() {
      RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this blog");
      parent::init();
   }
   
   function rss() {
      $rss = new RSSFeed($this->MyDataObject(), $this->Link(), "My feed", "Example feed.", "Title", "Content", "Author");
      $rss->outputToBrowser();
   }

Any idea?

Avatar
Howard

15 August 2009 at 4:58pm Community Member, 215 Posts

Hey yea I would also like to do something like this, any ideas?

Avatar
bartvanirsel

17 August 2009 at 9:50pm Community Member, 94 Posts

Hi,

I'm no expert but i think the link method in the data objects is used.

So if you create a custom Link method in your Data Object this will override the parent and will
also be used in the RSS feed.

Avatar
Howard

17 August 2009 at 10:19pm Community Member, 215 Posts

You're right, I figured this out yesterday so can confirm that it works :)

Avatar
go2planC

13 September 2010 at 6:09am Community Member, 19 Posts

Hi would be really usefull if you could supply the code you used here.

Thanks in advance :)

Avatar
Bauer-CTU

27 September 2010 at 11:33pm (Last edited: 27 September 2010 11:36pm), Community Member, 10 Posts

Like the OP I'm trying to create a RSS feed from DataObjects which do not each have their own page. However, I can't see how to create the custom Link method that is required. All the RSS entries for my feed should point to the same page where the Data Objects are listed.

So, I'd second go2planC - the code would be useful.

Thanks.

Avatar
Willr

29 September 2010 at 6:15pm (Last edited: 29 September 2010 6:16pm), Forum Moderator, 5511 Posts

However, I can't see how to create the custom Link method that is required. All the RSS entries for my feed should point to the same page where the Data Objects are listed.

Well you answered your own question. The page which stores your DataObject must have a URL of some sort which you can use as the return value from Link. Eg if you had a ListPage which printed out a list of objects your link function might look like

function Link() {
$holder = DataObject::get_one('ListPage');

return ($holder) ? $holder->Link() . '#item-'. $this->ID : false;

Which will generate you a link like http://yoursite.com/listpageurl#item-2. The #item-2 part is an anchor which if you're displaying posts all on the same page you can jump straight to item-2 if you have something like this setup in your html.

<div id="item-{$ID}">
// ...
</div>

If you don't want to link to anywhere just create a blank link function which links to say the homepage

function Link() {
return 'home';
}

Avatar
Bauer-CTU

29 September 2010 at 9:51pm Community Member, 10 Posts

Thanks Willr. I'll give that a go.