21490 Posts in 5783 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 226 Views |
-
check for DataObjects on this page

23 November 2011 at 5:46am
I want to include a piece of custom javascript....But
I only want this to happen if BannerPage has items in the DataObject Banner.
$this->ShowBanner can successfully check on a field within BannerPage.
But i want to check if this BannerPage actually has images in the Dataobject called Banner
---banner.php dataobject --that holds field bannerimage
class Banner extends DataObject {}
-- BannerPage --
class BannerPage extends Page {public static $db = array(
'ShowBanner' => 'Boolean'
);}
class BannerPage_Controller extends Page_Controller {
public function init() {
parent::init();
if($this->ShowBanner){
Requirements::customScript("myjscode",bannerjs');
}else {
}
}//init
}//controller
I previously did <% if Banners %> in template but i want to now add js via the Controller instead
Maybe i need to add a function ??
public function CheckBanners() {
return DataObject::get("Banner", "PageID = {$this->ID}");
} -
Re: check for DataObjects on this page

23 November 2011 at 1:55pm
I don't see any relationship between your BannerPage and the Banner object, such as has_one or has_many. But once you add a relationship, you can check for the existence of banners by doing this:
if($this->Banners()) {
//do something here
}
| 226 Views | ||
|
Page:
1
|
Go to Top |


