7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Random image from album
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | ||
| Author | Topic: | 1734 Views |
-
Re: Random image from album

16 February 2010 at 8:02am Last edited: 16 February 2010 8:15am
Thanks Banal! Works like a charm
So this is what I settled on:
In my TestimonialPage.php:
public function RandomTestimonial(){
return DataObject::get_one('Testimonial','',true, 'RAND()');
}In my TestimonialPage.ss
<div id="Mainbody">$RandomTestimonial.TestimonialImage</div>
Thanks again everyone,
SamPS: What is the difference between using false and true in the above function?
-
Re: Random image from album

16 February 2010 at 8:25am
The third argument is for "cache".. I have no idea, really. I assume it means that if you run the same query again, if true, it will just look in memory for the result of the query rather than running it again. I always use false.
-
Re: Random image from album

16 February 2010 at 9:57am
Hmm, sorting by Rand() wont make use of query cache, where as my previous method will.
Alternatively you could just make the user put the images in a specific folder and then grab one at random with PHP. Very quick.
-
Re: Random image from album

16 February 2010 at 11:26am
I don't think you'll be looking at significant speed increases when DataObject count is below several hundred or even thousands. You can still tweak the method for performance when you identify this as bottleneck, otherwise it's just premature optimization.
-
Re: Random image from album

16 February 2010 at 11:52am
Sigh.. Here comes banal again with the voice of reason. Come on, man! Don't ruin our fun!
| 1734 Views | ||
| Go to Top |



