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.

Archive /

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

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

DataObject::get_by_id() returns error


Go to End


2 Posts   3516 Views

Avatar
Double-A-Ron

Community Member, 607 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, 607 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