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.

Data Model Questions /

Quotation on every page using GridField


Reply


3 Posts   520 Views

Avatar
bones

Community Member, 104 Posts

7 March 2014 at 10:24am

Edited: 07/03/2014 10:24am

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 :)

Avatar
thomas.paulson

Community Member, 86 Posts

7 March 2014 at 5:40pm

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

Avatar
bones

Community Member, 104 Posts

8 March 2014 at 1:35am

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 :D