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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

Get random object

Go to End

20 Posts   10895 Views


Community Member, 72 Posts

2 September 2008 at 5:23pm

Edited: 02/09/2008 5:39pm

umm, nope. that would be my problem then. let me make the class and see what happens.


I created a new class/page called ProductsPage, and now I'm getting this error:
FATAL ERROR: Object::__call() Method 'forTemplate' not found in class 'ProductsPage'
At line 199 in /Applications/MAMP/htdocs/

maybe I'm missing something on the class stuff. After some good sleep I'll try again tomorrow.
Thanks for all your help guys.


Community Member, 72 Posts

2 September 2008 at 6:11pm

alright, I've been playing around with the get_one and get functions and when I use DataObject::get("ProductsPage", "", ""); it returns all the products, just like it should. then when I use DataObject::get_one('ProductsPage', null, false, 'RAND()'); I get the error that its looking for Object::__call() Method 'forTemplate' yet, Method 'forTemplate' not found in class 'ProductsPage',256. I'm starting to grasp this more and more, but maybe I'm missing the function or class to display the one result I want.

and then again maybe I'm just smoking something.


Forum Moderator, 922 Posts

2 September 2008 at 6:18pm

Edited: 02/09/2008 6:22pm

forTemplate() usually means you're referencing an object in a template, but it doesn't know how to render it.

This could mean that you're doing something like $RandomObject - when it should be in specific calls to properties on that object such as $RandomObject.Title OR using <% control RandomObject %> to render variables in the scope of that object.


Community Member, 72 Posts

3 September 2008 at 2:33am

That was it. I put .Title behind it and it worked perfectly.

Thanks for all the help.

Go to Top