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.

General Questions

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

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

Multiple Images Per Page


Reply

4 Posts   1449 Views

Avatar
arsenic

6 January 2010 at 5:05pm (Last edited: 6 January 2010 5:06pm), Community Member, 9 Posts

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

6 January 2010 at 7:04pm Community Member, 19 Posts

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
Pigeon

7 January 2010 at 2:10pm Community Member, 243 Posts

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

21 January 2010 at 3:38am Community Member, 56 Posts

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?