Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Access a $db-field in Parent page of Page with DataObject and saving images to custom folder in 2.4

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

Page: 1
Go to End
Author Topic: 848 Views
  • KINKCreative
    Avatar
    Community Member
    56 Posts

    Access a $db-field in Parent page of Page with DataObject and saving images to custom folder in 2.4 Link to this post

    Hi guys. I have a "holder" page that is holding subpages, one of which is a simple one album gallery. I have an AssetFolder field in the $db of the holder page to name the subfolder in /assets that all the files from any subpage upload will be stored in. I am trying to setup an AlbumImage class, that would save in the /assets/AssetFolder/images class, for example.

    Firstly, I would like to know how to access the AssetFolder from my class if the tree is like this:

    Holder > OneAlbumGallery Page > Dataobject (AlbumImage)

    class AlbumImage extends DataObject {
       
       static $db = array(
          'Name' => 'Text',
          'Description' => 'Text',
       );
       
       static $has_one = array (
          'File' => 'Image',
          'Page' => 'OneAlbumGallery'
       );
       
       function getCMSFields_forPopup() {
          //$assetFolder = $this->Page->Parent->AssetFolder();
          return new FieldSet(
             new TextField('Name'),
             new TextareaField('Description'),
             new SimpleImageField('File','Select image',null,null,null,$assetFolder.'/images')
          );
       }
    }

    Secondly, it seems that even if I enter the correct AssetFolder by hand in the code above, the images are still saved in the Uploads. I thought this had been resolved in 2.4? Maybe I'm using the wrong syntax?

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