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:

Data Model Questions /

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

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

Go to End



Community Member, 66 Posts

1 August 2010 at 5:49pm

Edited: 01/08/2010 5:53pm

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?