22853 Posts in 9936 Topics by 2804 members
|Go to End|
6 January 2010 at 5:05pm Last edited: 6 January 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?
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.
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
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 ImageField("image1","Main image",null,null,null,"assets/myFolder/"),
$fields->push(new ImageField("gallery","Image gallery",null,null,null,"assets/myFolder/"));
The upload/attach for the main image is fine, but in the popup 'Image gallery' appears as a single File upload.
|Go to Top|