Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Dataobject as pages using 2 images

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

Page: 1
Go to End
Author Topic: 397 Views
  • Mauro74
    Avatar
    Community Member
    30 Posts

    Dataobject as pages using 2 images Link to this post

    I'm trying to develop a tutorial from http://www.ssbits.com that uses Dataobject as pages. Here's the link to it: http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple

    Now in the tutorial (which I've used already in my projects) there's only one image per staff member, I want to associate 2 images per staff member (I've used products instead of staff members), I guess I need to use $has_many relation but when I try it doesn't work properly, it uploads the images but it doesn't associate them with the staff member (product in my case). Here's how I did it:

    //Relations
    static $has_one = array (
    'ProductPage' => 'ProductPage'
    );

    static $has_many = array (
    'Photo1' => 'Image',
    'Photo2' => 'Image'
    );

    Anyone know how to do this?

    Thanks

  • Bolixe
    Avatar
    Community Member
    17 Posts

    Re: Dataobject as pages using 2 images Link to this post

    Hi there!!

    It´s remain me something I have used with my dataObject to upload multiple files.

    Create a extra class:

    class ProductImages extends File
    {
    static $has_one = array (

    'yourDataObject' => 'yourDataObject'

    );
    }

    Then your relations in yourDataObject should be like:

    //Relations
    static $has_one = array (
    'ProductPage' => 'ProductPage'
    );

    static $has_many = array (
    'ProductImages ' => 'ProductImages'
    );

    In templates:

    <% if ProductImages%>

    <p>Images</p>

    <% control ProductImages%>

    <a href="$Filename">$Title</a>

    <% end_control %>

    <% end_if %>

    Then to make it better, in the getCMSFields you can limit the number of uploads per object

    Cheers

    397 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.