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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Rss Link


Go to End


9 Posts   3586 Views

Avatar
bebabeba

Community Member, 193 Posts

5 January 2011 at 8:45pm

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

Forum Moderator, 5523 Posts

6 January 2011 at 8:58pm

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

Community Member, 193 Posts

27 January 2011 at 11:52pm

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

Forum Moderator, 5523 Posts

28 January 2011 at 9:46am

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

Community Member, 193 Posts

31 January 2011 at 8:56pm

Edited: 31/01/2011 11:49pm

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

Community Member, 193 Posts

31 January 2011 at 11:55pm

Edited: 01/02/2011 8:52pm

Any idea?

Avatar
bebabeba

Community Member, 193 Posts

3 February 2011 at 3:51am

help please..

Avatar
Willr

Forum Moderator, 5523 Posts

4 February 2011 at 3:42pm

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