Jump to:

23471 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [Solved] One Photo, Several Pages

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

Page: 1
Go to End
Author Topic: 625 Views
  • tonito
    Avatar
    Community Member
    24 Posts

    [Solved] One Photo, Several Pages Link to this post

    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.

  • tonito
    Avatar
    Community Member
    24 Posts

    Re: [Solved] One Photo, Several Pages Link to this post

    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.

    625 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.