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.

Archive /

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

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

DataObject::get_by_id() returns error


Reply


2 Posts   2261 Views

Avatar
Double-A-Ron

Community Member, 604 Posts

15 June 2008 at 7:25pm

Edited: 15/06/2008 7:26pm

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

Avatar
Double-A-Ron

Community Member, 604 Posts

15 June 2008 at 7:32pm

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