Jump to:

23377 Posts in 18296 Topics by 2868 members

General Questions

SilverStripe Forums » General Questions » Rss Link

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

Page: 1 2
Go to End
Author Topic: 2470 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    Rss Link Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Rss Link Link to this post

    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.

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: Rss Link Link to this post

    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!

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Rss Link Link to this post

    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.

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: Rss Link Link to this post

    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..

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: Rss Link Link to this post

    Any idea?

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: Rss Link Link to this post

    help please..

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Rss Link Link to this post

    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));
    ...

    2470 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.