Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Quotation on every page using GridField

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

Page: 1
Go to End
Author Topic: 393 Views
  • bones
    Avatar
    Community Member
    104 Posts

    Quotation on every page using GridField Link to this post

    Hello
    I'm finally moving up to SS3 from 2.4! My previous site used DOM for a list of quotations, and I then used the following code in page.php to display a random quotation on every page.

    public function RandomQuotes()
    {
    $limit = 1;
    return DataObject::get("Quote",null,"RAND()",null,$limit);
    }


    I've got GridField working. But I can't work out how to modify the above code to give me the same result as previously.

    All help appreciated. Thanks

  • thomas.paulson
    Avatar
    Community Member
    72 Posts

    Re: Quotation on every page using GridField Link to this post

    public function RandomQuotes()
    {
    $limit = 1;
    return Quote::get()->sort('RAND()') ->limit($num);
    }

  • bones
    Avatar
    Community Member
    104 Posts

    Re: Quotation on every page using GridField Link to this post

    Thanks, Thomas. I've very grateful for your reply.

    The code you supplied didn't work properly but you pointed me in the right direction. Here's the working version:

    public function RandomQuotes()
    {
    return Quote::get()->sort('RAND()') ->limit(1);
    }


    Thanks again

    393 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.