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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Rss Link


Go to End
Reply

9 Posts   2529 Views

Avatar
bebabeba

5 January 2011 at 8:45pm Community Member, 192 Posts

Hi!
I need ti change default link of RssFeed.
I create a function that ask data to external db. so at the and of my function have:

function query_ext() {
......query thak extract data ....
$doSet = new DataObjectSet();
while (...){
$result = array(
'Title'=> $titolo,
'Abstract'=> $abstract,
'My_Link'=> $my_link, );
$doSet->push(new ArrayData($result));}
return $doSet;
}

and I wrote this in my controller:

function rss() {

$rss = new RSSFeed($this->query_ext(), 'My_Link', "I Feed RSS", "My feed are:", "Title", "Abstract", "Author");
$rss->outputToBrowser();
}

In my rss page I see title and abstract but not link. can you help me to find error?

Avatar
Willr

6 January 2011 at 8:58pm Forum Moderator, 5511 Posts

The link parameter which you have used for My_Link is for the link to the RSS feed not each item in particular. I believe RSSFeed would assume that all entries are subclasses of DataObject and have either AbsoluteLink() or Link() functions defined. Try change My_Link to Link in your while loop and see if it picks up 'Link' by default, otherwise you will need to define a actual dataobject class for it.

Avatar
bebabeba

27 January 2011 at 11:52pm Community Member, 192 Posts

Hi Willr!
I try to change My_link in Link but nothing change.
Can you help me to create a correct function? I'm unable to solve this problem..
Thnaks!

Avatar
Willr

28 January 2011 at 9:46am Forum Moderator, 5511 Posts

I try to change My_link in Link but nothing change

Try AbsoluteLink(). It is possible that it won't work at all if it calls the method since of course your object isn't an dataobject. You may have to create those objects as DataObject subclasses for it to call Link() on.

Avatar
bebabeba

31 January 2011 at 8:56pm (Last edited: 31 January 2011 11:49pm), Community Member, 192 Posts

Hi Willr..
sorry but I'm unable to correct my example..
I try in this way
$result = array(
          'Title'=> $titolo,
          'Abstract'=> $abstract,
          'mylink'=> $id, );
$doSet->push(new ArrayData($result));

function rss() {
      $rss = new RSSFeed($this->solr_ss(), $this->Link(), "I Feed RSS", "Article:", "Title", "Abstract", "mylink","Author");
      $rss->outputToBrowser();
   }

In RssFeed.php I add a field $mylinkField

and in .ss
<% control Entries %>
      <item>
         <title>$Title.XML</title>
         <link>$AbsoluteLink</link>
         <% if Description %><description>$Description.AbsoluteLinks.EscapeXML</description><% end_if %>
         <% if Mylink %><mylink>$mylink</mylink><% end_if %>
         <% if Date %><pubDate>$Date.Rfc822</pubDate>
         <% else %><pubDate>$Created.Rfc822</pubDate><% end_if %>
         <% if Author %><dc:creator>$Author.XML</dc:creator><% end_if %>
         <guid>$AbsoluteLink</guid>
      </item>
      <% end_control %>
I can see link in the example but if i put:
<link>$mylink</link>
I enter always in user_error..

Avatar
bebabeba

31 January 2011 at 11:55pm (Last edited: 1 February 2011 8:52pm), Community Member, 192 Posts

Any idea?

Avatar
bebabeba

3 February 2011 at 3:51am Community Member, 192 Posts

help please..

Avatar
Willr

4 February 2011 at 3:42pm Forum Moderator, 5511 Posts

Hi Bebabeba,

Have you tried looking at the code for RSSFeed? This is the function which generates the $AbsoluteLink string you posted in your template example.

   function AbsoluteLink() {
      if($this->failover->hasMethod('AbsoluteLink')) return $this->failover->AbsoluteLink();
      else if($this->failover->hasMethod('Link')) return Director::absoluteURL($this->failover->Link());
      else user_error($this->failover->class . " object has either an AbsoluteLink nor a Link method. Can't put a link in the RSS feed", E_USER_WARNING);
   }

As you can see it calls hasMethod(). I am not sure if hasMethod() will pick up the fact that you have an array of data (rather than an object).

So what I think you need to do, as I mentioned in my first post is to use a proper object rather than simply an Array.

// new class - RSSFeedableData.php
class RSSFeedableData extends ArrayData {

function Link() { return $this->getField('Link'); }
}

// change your function like
$result = array(
'Title'=> $titolo,
'Abstract'=> $abstract,
'Link'=> $id
);

$doSet->push(new RSSFeedableData($result));
...

Go to Top