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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

multiple images on all pages


Go to End


3 Posts   903 Views

Avatar
danzzz

Community Member, 175 Posts

18 February 2012 at 3:50am

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?

Avatar
martimiz

Forum Moderator, 1391 Posts

18 February 2012 at 8:58am

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

Avatar
Mo

Community Member, 541 Posts

21 February 2012 at 12:05am

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