I knew how to do this in SS2.X, but having problem in SS3. The background image is added in the CMS via SiteConfig.
I have BackgroundImage.php
class BackgroundImage extends DataObject {
public static $has_one = array(
'BackgroundImage' => 'Image',
'SiteConfig' => 'SiteConfig'
);
...
}
I have SiteConfigCustom.php
class SiteConfigCustom extends DataExtension {
public static $has_many = array(
'BackgroundImages' => 'BackgroundImage'
);
...
}
my old way:
Page.php
function RandomImage() {
return dataobject::get_one("BackgroundImage","SiteConfigCustomID",true,"Rand()");
}
A couple I've tried (but the function makes the page break):
Page.php
function RandomImage() {
return BackgroundImage::get()->sort('RAND()');
and
return BackgroundImage::get()->filter('SiteConfigCustomID')->sort('RAND()');
}
Any help much appreciated.