Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » DataObject::get_by_id() returns error

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2071 Views
  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    DataObject::get_by_id() returns error Link to this post

    Hi (again). I have added a dropdown box to my page type "Tour". This Dropdown box contains the site tree. The purpose of it is to link one Tour to another (beacuse the tours are offered in reverse itineraries). This works well, and saves the value of the select Reverse Tour in a field called ReversTourID.


    Now I am trying to access this reverse tour and add a link in the template to that page. I have found other threads on this and have added a function to Tour.php (which extends Page)

    function GetReverseTour() {
          $thisPage = DataObject::get_by_id("Page",$this->ReverseTourID);
          return $thisPage;
       }


    I have also tried replacing "Page" with "Tour", but in debug mode, I get this error when I call the above function:

    FATAL ERROR: Object::__call() Method 'forTemplate' not found in class 'Tour'


    Any Ideas? Am I out of the DataObject scope here? Isn't page a decendant of SiteTree, and thus DataObject?
    Cheers
    Aaron

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: DataObject::get_by_id() returns error Link to this post

    Dammit, I figured it out (again).
    It was returning an entire page object. I had to call the function like so:

    GetReverseTour.Link


    If I wanted the link that is. I guess the existing page simply didn't know what to do with the data that was returned.
    Cheers
    Aaron

    2071 Views
Page: 1
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.