11/05/2012 3:57pm

PHP | Problem - Slides from Siteconfig, no display :(


<?php 

class SiteConfigOverride extends DataObjectDecorator{
function extraStatics() {
return array('has_many' => array(
'SliderA' => 'SingleASlide'
));
}

public function updateCMSFields(FieldSet &$fields) {

$fields->addFieldToTab('Root.SliderA', new ComplexTableField(
$this->owner, 'SliderA', 'SingleASlide',
array('SlideImg' => 'Afbeelding van slide', 'SlideTitle' => 'Titel van Slide', 'SlideCaption' => 'Tekst bij slide', 'SlideLink.Title' => 'Link naar pagina'
)));
}
}
?>


<?php
class SingleASlide extends DataObject
{
static $has_one = array (
'SlideImg' => 'Image',
'SlideLink'=> 'SiteTree',
);
static $db = array (
'SlideTitle' => 'Text',
'SlideCaption' => 'Text',
);

public function getCMSFields_forPopup()
{
return new FieldSet(
new LiteralField('SlideImgWar', '<p><strong>Let op!</strong><br />Afbeelding moet 200 * 135 (in px) zijn!</p>'),
new ImageUploadField('SlideImg', 'Afbeelding van slide'),
new TextField('SlideTitle'),
new TextField('SlideCaption'),
new SimpleSiteTree('SlideLinkID')
);
}
}
?>


1 Comments 1 Solutions

14/05/2012 3:12am

PHP | Solution - Anonymous

The first thing you need to do in updateCMSFields is push a new HiddenField('ID'). ComplexTableField relies on this hidden field to set the ID of the objects it manages. You'll find in your database that all the current slide objects have the parentID of 0, which is why they don't show up on the frontend.

public function updateCMSFields(FieldSet &$fields) {
$fields->push(new HiddenField('ID', '', $this->owner->ID));
...

Post Comment