3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 432 Views |
-
Showing HasManyComplexTableField data on every page - weird problem

16 September 2011 at 3:34am
Hi
On my "HomePage.php", I'm using the following:
$tablefield = new HasManyComplexTableField(
$this,
'Banners',
'Banner',
array(
'BannerImage' => 'Banner Image',
'BannerText' => 'Banner Text'
),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle( 'Banner' );
$fields->addFieldToTab( 'Root.Content.Banner', $tablefield );
Together with "Banner.php":<?php
class Banner extends DataObject {
static $db = array(
'BannerText' => 'Varchar(100)'
);
static $has_one = array(
'Page' => 'Page',
'BannerImage' => 'Image'
);
function getCMSFields_forPopup() {
return new FieldSet(
new TextareaField('BannerText'),
new ImageField('BannerImage')
);
}
}
?>
So far so good- everything works. However, I want to display these same items on every page throughout the website. So in "Page.php", I added the following:public function BannerBox(){
return DataObject::get("Banner");
}
Initially, this seemed OK too, displaying the items throughout the site. Then I realised that the items were being displayed regardless of whether they were enabled (ie regardless of whether the tickbox in the popup was ticked or not). Am I using the correct method to call the data onto each page, or is this a bug?Many thanks
-
Re: Showing HasManyComplexTableField data on every page - weird problem

16 September 2011 at 3:57am
Maybe I misunderstand you, but I see no reference to any 'enable' boolean or checkbox in your Banner Object? Anyway, if there was one, you could check on it in your DataObject::get, and that would be that...
-
Re: Showing HasManyComplexTableField data on every page - weird problem

16 September 2011 at 4:05am
Sorry, I've made an error in my information. The tickbox isn't in the popup, it's next to the entry (see attached file).
The weird thing is that using
public function BannerBox(){
return DataObject::get("Banner");
}
completely ignores the tickbox. If I omit this code, the tickbox works correctly (but the info is confined to just the homepage. -
Re: Showing HasManyComplexTableField data on every page - weird problem

16 September 2011 at 4:32am
OK, I that that one links the banners that are checked to your homepage, but it doesn't really disable their further use within the website. If you want to do it like this, you could maybe do something like this (simplyfied):
$homepage = DataObject::get_one('Sitetree', "ClassName = 'HomePage'");
return $homepage->Banners(); -
Re: Showing HasManyComplexTableField data on every page - weird problem

16 September 2011 at 4:39am
Fantastic! Works perfectly. Thank you so much
| 432 Views | ||
|
Page:
1
|
Go to Top |

