I've been working on getting a random banner going and after wading through several tutorials all is working. In the Page_Controller of Page.php I have:
public function RandomBanners() {
$foldername = "bannerimgs";
$folder = Folder::findOrMake($foldername);
return DataObject::get("Image", "ParentID = $folder->ID", "RAND()", '', 3);
}
Under the init function I added:
Requirements::javascript("mysite/javascript/jquery-1.3.2.min.js");
Requirements::javascript("mysite/javascript/jquery.cycle.lite.1.0.js");
Requirements::customScript("
jQuery(document).ready(function(){
jQuery('#bannerimages').cycle({ delay: 5000, speed: 4000 });
jQuery('#bannerimages').show();
});"
);
In Page.ss:
<div id="bannerimages">
<% control RandomBanners %>
<img src="$URL" width="$width" height="$height" alt="" />
<% end_control %>
</div>
And no problems, however if there are better ways to do the above please feel free to let me know. But now I would like to be able to select a different folder based on the current page ID. For example, if I'm on the homepage and it has a page ID of 1 I might want to select the random images from a different folder. I've tried adding:
public function RandomBanners() {
if($this ->ID = 1) {
$foldername = "newfolder";
}
else {
$foldername = "bannerimgs";
}
$folder = Folder::findOrMake($foldername);
return DataObject::get("Image", "ParentID = $folder->ID", "RAND()", '', 3);
}
And what it appears to be doing is checking to see if any of the pages using the Page class have an ID of 1, and not the CURRENT page. So of course, if I use the ID of any real page it always uses the same folder.
Basically, all I want to be able to do is to check inside a function if the page I am on has an ID of 1 and then proceed accordingly.
Any ideas? All help appreciated.
TIA