Jump to:

23360 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » multiple images on all 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: 453 Views
  • danzzz
    Avatar
    Community Member
    175 Posts

    multiple images on all pages Link to this post

    hi,

    my Page.php:

    public static $has_many = array(
        'Slides' => 'MyImage'
       );

    ...

    $slides = new MultipleImageUploadField('Slides', 'Slides');
    $fields->addFieldToTab("Root.Content.Slider", $slides);

    MyImage.php

    class MyImage extends Image {

    static $has_one = array (
       'Page' => 'Page'
    );

    }

    so, with this I only cann a image to 1 page. If I want add an image also to an other Page it dont work, I cant choose it in uploadify window, its disabled.

    this:

    class MyImage extends Image {

    static $has_many = array (
       'Pages' => 'Page'
    );

    }

    also dont work. If I do this, it dont work any more.

    How to solve this issue?

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: multiple images on all pages Link to this post

    I don't quite get what you're doing, but having two objects relate 'has_many' to each other won't work. Opposite every $has_many there needs to be a $has_one that holds the ID

    The alternative is to do a $many_many / $belongs_many_many relation, where a new table will be created to link the two

  • Mo
    Avatar
    Community Member
    504 Posts

    Re: multiple images on all pages Link to this post

    I am not sure if this is what you mean, but if you want attached images to appear on all pages, but only be attached to one (say the homepage), then you can use the Page() controller to find your page and access its data model. More info is here:

    http://doc.silverstripe.org/sapphire/en/reference/built-in-page-controls#controlling-certain-pages

    You would use this by adding something like this to your template:

    <% control Page(home) %><% control Slides %><img src="$URL" /><% end_control %><% end_control %>

    That what you are after?

    Mo

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