Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

DOM control loop template in siteconfig


Go to End


5 Posts   2519 Views

Avatar
badjedi

Community Member, 25 Posts

29 April 2012 at 12:42am

I am Swf banner, that randomly rotates for each page.

I have made a Dataobject, with file upload and alternate text/images fine in CMS.

But When trying to loop thru in templates i get no data even tho i see several items in the DOM inside siteconfig.

Avatar
badjedi

Community Member, 25 Posts

29 April 2012 at 12:46am

Here's my Dataobject code(SwfBannerResource.php)

<?php

class SwfBannerAdResource extends DataObject
{
static $db = array (
'AdName' => 'Text',
'Link' => 'Text'

);

static $has_one = array (
'Attachment' => 'Image', //Needs to be an image
'Swf' => 'File',

'SiteConfig' => 'SiteConfig'

);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('AdName'),
new TextField('Link'),
//new FileIFrameField('Attachment'),
new FileAttachmentField('Attachment', 'Static jpeg 1017px by 112px'),
new FileAttachmentField('Swf', 'Swf 1017px by 112px')

);
}
}

Here's my Site config (part of it)

public function updateCMSFields(FieldSet &$fields) {

$manager = new DataObjectManager(
$this->owner,
'SwfBanners',
'SwfBannerAdResource',
//'Swf',
array(
'AdName' => 'AdName',
'Link' => 'Link',
'Attachment.Name' => 'Attachment',
'Swf.Name' => 'Swf',

),
'getCMSFields_forPopup'
);
$manager->setParentClass('SiteConfig');
$manager->setSourceID($this->owner->ID);
/*
$manager->setUploadFolder("PublicationPage-" . $this->ID);
$manager->setAllowedFileTypes(array ('pdf','doc'));
*/

$fields->addFieldToTab("Root.SwfBanner", $manager);

And here's my template:

<% control SiteConfig %>

<% control SwfBanners %>
$Attachment
<div id="FlashContainer">
<a href="$Link">
$Attachment
</a>
</div>
<script type="text/javascript">
/* <![CDATA[ */
swfobject.embedSWF(
"$Swf.URL",
"FlashContainer",
"1017", "112",
"9.0.0",
"nzkier2/nzskier/js/swfobject/expressInstall.swf"
);
/* ]]> */
</script>
<% end_control %>
<% end_control %>

I haven't got randomizing yet, I'm just trying to loop thru all the SwfBanner data object and get them to display.

But only "/assets/" is output by the template even tho in the CMS i can see the files, urls, etc.

Any Ideas?

Thanks in advance

Avatar
mrcl

Community Member, 8 Posts

22 May 2012 at 1:44am

Edited: 22/05/2012 2:21am

I am having the same sort of problem....
Is there anybody who could help us with that?

I can access any field I create in any tab of the SiteConfig. however when I try to run a control loop to a

// Relation into SiteConfig extension

$has_many=array('Cars'=>'Car');

// Relation into DataObject extension (Car)

$has_one=array('SiteConfig'=>'SiteConfig');

The following loop
// .ss File

<% SiteConfig %>
   <% Cars %>
      <li>.........</li>
   <% end_control %>
<% end_control %>

does not return any element from the list that I can manage using DataObjectManager(this works very smooth), which seats on a new Tab created in the SiteConfig.
It is like Cars does not exist.

Thanks in advance....

PS: This Forum has been clarified lot of my doubts!!! (But I still have a lot to go....)

Cheers to you all..

Avatar
mrcl

Community Member, 8 Posts

22 May 2012 at 2:18am

I tried to create the following function at Page_Controller class

function CarList() {
         return DataObject::get('Car');
   }

then created a control loop to CarList in my template.
no success....

Avatar
mrcl

Community Member, 8 Posts

22 May 2012 at 2:36am

Edited: 22/05/2012 2:37am

Solution....

Instead of creating the function inside the Page_Controller, I inserted this function inside the Decorator class that extends the Page_Controller.

Example:

   class CarGalleryDecorator_Config extends DataObjectDecorator {
      ..... // Here I define the relations and create a new tab that holds the DOM
   }

   class CarGalleryDecorator_Controller extends Extension {

      function SidebarLinkList() {
         return DataObject::get('SidebarLink');
      }
   }

and in mysite/_config.php

Object::add_extension('Page_Controller', 'CarGalleryDecorator_Controller');
DataObject::add_extension('SiteConfig', 'CarGalleryDecorator_Config');

For some reason I would think that what was done in the previous post would work the same way as this one.
But not....

By the way, happier now that it works!!!!