Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DOM control loop template in siteconfig

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1859 Views
  • badjedi
    Avatar
    Community Member
    25 Posts

    DOM control loop template in siteconfig Link to this post

    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.

  • badjedi
    Avatar
    Community Member
    25 Posts

    Re: DOM control loop template in siteconfig Link to this post

    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

  • mrcl
    Avatar
    Community Member
    8 Posts

    Re: DOM control loop template in siteconfig Link to this post

    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..

  • mrcl
    Avatar
    Community Member
    8 Posts

    Re: DOM control loop template in siteconfig Link to this post

    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....

  • mrcl
    Avatar
    Community Member
    8 Posts

    Re: DOM control loop template in siteconfig Link to this post

    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!!!!

    1859 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.