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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

->setFolderName with Page Title


Go to End


3 Posts   1531 Views

Avatar
socks

Community Member, 191 Posts

16 March 2013 at 8:46pm

I have multiple gallery pages (OurWorkPage) and would like to have a distinct setFolderName for each one. I've successfully added the ID to the folder name, but what I really want is the Title or MenuTitle of OurWorkPage.

class ProjectImage extends DataObject {

   public static $has_one = array(
      'OurWorkPage' => 'OurWorkPage',
      'ProjectImage' => 'Image'
   );

   function getCMSFields() {
      $fields = parent::getCMSFields();

      $imageField = new UploadField('ProjectImage','Project Image');     
      $imageField->setFolderName('Our-Work-Images-'.$this->OurWorkPageID);
      
       …
    }

}

Thanks

Avatar
martimiz

Forum Moderator, 1391 Posts

18 March 2013 at 1:17am

Something like this?

$imageField->setFoldername($this->OurWorkPage()->URLSegment);

Avatar
socks

Community Member, 191 Posts

18 March 2013 at 6:25am

That worked :)

$imageField->setFolderName($this->OurWorkPage()->MenuTitle.'-Work-Images');

Thank you!