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

[Solved] One Photo, Several Pages


Go to End


2 Posts   1342 Views

Avatar
tonito

Community Member, 24 Posts

20 August 2010 at 2:24am

Edited: 23/08/2010 2:18pm

I added a photo to a page with the following method (actually to a Product in the ecommerce module to be more precise):

static $has_one = array(
'Photo' => 'Image'
);

and

function getCMSFields($cms) {
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
return $fields;
}

I have photos in an asset folder. I can only associate each of these photos to only one page, as soon as the photo is used, it becomes unavailable for selection to other pages.

Could someone please help? I suspect it's a one to many type relationship I need to develop, but I am lost at this stage.

Avatar
tonito

Community Member, 24 Posts

23 August 2010 at 2:18pm

I have a solution.

In ecommerce, Product_Image seems to only attach file to an image, by that I mean that if I add a file from a From the File Store, I can only select one image per specific product.

Changing to this in Product php:
public static $has_one = array(
'MyImage' => 'Image',
);

instead of:

public static $has_one = array(
'MyImage' => 'Product_Image',
);

solved my issue.