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:

Data Model Questions /

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

Quotation on every page using GridField


Go to End


3 Posts   926 Views

Avatar
bones

Community Member, 110 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, 107 Posts

7 March 2014 at 5:40pm

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

Avatar
bones

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