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

Multiple Images Per Page


Go to End


4 Posts   1972 Views

Avatar
arsenic

Community Member, 9 Posts

6 January 2010 at 5:05pm

Edited: 06/01/2010 5:06pm

I need to associate multiple images with a page. Do I use has_many Image on the page? Or do I use has_many DataObject on the page where the DataObject has_one Image? What's the best way to do this?

Avatar
marblegravy

Community Member, 19 Posts

6 January 2010 at 7:04pm

I think it depends on how many images you need and how you plan on displaying them.

If all you want is a Gallery style setup, then setting up a new DataObject for the page would be your best bet (of go check out the Gallery Module...). The SS Book has a good demo you can adjust easily using Jobs and Job Categories... I'm sure there's a similar tutorial around here somewhere.

If you have set places you want them all to go, you might want to consider just setting up individual fields for each item on the Page and coding their placeholders in to the layout.

Avatar
dhensby

Community Member, 253 Posts

7 January 2010 at 2:10pm

Like marblegravy said, it depends how you want to display them. If you literally just want to relate many images, then $has_many is fine and i would use something like: http://doc.silverstripe.org/doku.php?id=modules:DataObjectManager#imagedataobjectmanager to manage them :)

Avatar
mattclegg

Community Member, 56 Posts

21 January 2010 at 3:38am

I want to display a gallery of images per product & a main image. I have;

class Product extends DataObject
{
static $db = array (
'Name' => 'Text'
);

static $has_one = array (
'image1' => 'Image',
);

static $has_many = array (
'gallery' => 'Image'
);

public function getCMSFields_forPopup()
{
$fields = new FieldSet(
new TextField('Name'),
new ImageField("image1","Main image",null,null,null,"assets/myFolder/"),
);

$fields->push(new ImageField("gallery","Image gallery",null,null,null,"assets/myFolder/"));

return $fields;
}
}

The upload/attach for the main image is fine, but in the popup 'Image gallery' appears as a single File upload.

Any ideas?