Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Get random object

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

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

Page: 1 2 3
Go to End
Author Topic: 9290 Views
  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

    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/biomicro.com/sapphire/core/Object.php

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

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

    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.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Get random object Link to this post

    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.

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

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

    Thanks for all the help.

    9290 Views
Page: 1 2 3
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.