Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Default Upload Folder (DOM with Nested FileDOM)

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: 918 Views
  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Default Upload Folder (DOM with Nested FileDOM) Link to this post

    Hi All:

    I have a Dataobject set up with a nested FileDataObect. I am trying to set the default upload folder for the FileDataObject, but keep getting the error message that the "method 'setuploadfolder' does not exist on 'DataObjectManager'"

    I understand why, which is because the DataObject is not a file. So I am unsure where I am supposed to note the default upload folder for the nested FileDOM. Can someone point out where it should go? I have the following snippit

    $manager->setUploadFolder('SafetyAZImages');

    but am guessing it has to change a bit to accommodate the nested object. Here is the code:

    Thanks as always for the support!

    SafetyAZPage.php

    class SafetyAZPage extends Page
    {
       static $has_many = array (
          'SafetyAZItems' => 'SafetyAZItem'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new DataObjectManager(
             $this, // Controller
             'SafetyAZItems', // Source name
             'SafetyAZItem', // Source class
             array('AZTitle' => 'AZTitle'), // Headings
             'getCMSFields_forPopup' // Detail fields function or FieldSet
             // Filter clause
             // Sort clause
             // Join clause
          );
          
          
          $f->addFieldToTab("Root.Content.SafetyAZItems", $manager);
          
          return $f;
       }

    }

    SafetyAZItem.php

    <?php
    class SafetyAZItem extends DataObject
    {
       static $db = array (
          'AZTitle' => 'Text',
          'AZContent' => 'Text'
       );
       
       static $has_one = array (
          'SafetyAZPage' => 'SafetyAZPage'
       );
       
       static $has_many = array (
          'SafetyAZImages' => 'SafetyAZImages'      
          );
       
       public function getCMSFields()
       {
          return new FieldSet(
             new TextField('AZTitle'),
             new TextareaField('AZContent'),
             new FileDataObjectManager(
                $this,
                'SafetyAZImages',
                'SafetyAZImage',
                'AZImage',
                array('AZImageTitle' => 'AZImageTitle',
                    'AZImageCaption' => 'AZImageCaption')   
             
             )
             
          );
       }
    }
    ?>

    SafetyAZImage.php

    <?php
    class SafetyAZImage extends DataObject
    {
       static $db = array (
          'AZImageTitle' => 'Text',
          'AZImageCaption' => 'Text'
       );
       
       static $has_one = array (
          'SafetyAZItem' => 'SafetyAZItem',
          'AZImage' => 'File'
       );
       
          
       function getCMSFields()
       {
          return new FieldSet(
             new TextField('AZImageTitle'),
             new TextField('AZImageCaption'),
             new FileIFrameField('AZImage')
             
          );
             
       }
    }
    ?>

  • UncleCheese
    Avatar
    4085 Posts

    Re: Default Upload Folder (DOM with Nested FileDOM) Link to this post

    What about this:

    public function getCMSFields()
    {
    $f = new FieldSet(
    new TextField('AZTitle'),
    new TextareaField('AZContent'),
    $fdom = new FileDataObjectManager(
    $this,
    'SafetyAZImages',
    'SafetyAZImage',
    'AZImage',
    array('AZImageTitle' => 'AZImageTitle',
    'AZImageCaption' => 'AZImageCaption')

    )

    );
    $fdom->setUploadFolder("foo");
    return $f;
    }

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: Default Upload Folder (DOM with Nested FileDOM) Link to this post

    You're the man! Thanks UC!

    Also:

    I noticed in SafetyAZItem.php I had:

    static $has_many = array (
    'SafetyAZImages' => 'SafetyAZImages'
    );

    should it actually be...

    static $has_many = array (
    'SafetyAZImages' => 'SafetyAZImage'
    );

    or does that not matter?

    I did change it to the latter though.

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