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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager


Go to End


10 Posts   3643 Views

Avatar
yug

Community Member, 17 Posts

22 February 2011 at 6:43pm

Hi everyone

So i am trying to set up the ability to manage Banners. I need the ability for different pages to have different banners and in different orders. It would be nice so that when i add a Banner for a certain page, this banner is also automatically available for another page type. So my idea is to loop through a folder in assets, and link every image to that page.

I have created a BannerImage class and currently have it working so that when i upload an image, other pages can see this image. However if i rearrange this image on one particular page, it changes in all the other pages

Can anyone help please?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 February 2011 at 10:52am

Sounds like you want a ManyManyFileDataObjectManager? That will allow you to upload banners from every page, and choose which banners you want, new or existing, to appear on any given page.

Avatar
yug

Community Member, 17 Posts

23 February 2011 at 12:05pm

Ok so i think i have this set up.....so when i add an image, i can see this image on all pages. But if i change the order of the images on one page, it changes the order on every other page

Can you please help me in setting this up properly

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 February 2011 at 12:38pm

Yeah, I think somewhere in this forum you'll see a write up on SortableDataObject::add_sortable_many_many_relation();.. I think it's in a sticky.

Avatar
yug

Community Member, 17 Posts

23 February 2011 at 1:31pm

I cant seem to find anything and what is a sticky

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 February 2011 at 2:44pm

Avatar
yug

Community Member, 17 Posts

23 February 2011 at 4:30pm

Can you see where i am going wrong

BannerImage.php
-------------------------------------------------------------------------------------

<?php

class BannerImage extends DataObject {

static $db = array(
'Title' => 'Text',
'URL' => 'Text'
);

static $has_one = array(
'BannerImage' => 'Image'
);

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

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('URL'),
new FileIFrameField('BannerImage')
);
}
}

?>

Page.php
-----------------------------------------------------

<?php
class Page extends SiteTree {

public static $db = array(
);

public static $has_one = array(
);

static $many_many = array(
"BannerImages" => "BannerImage"
);

public function getCMSFields() {

$fields = parent::getCMSFields();

$idom = new ManyManyFileDataObjectManager (
$this,
'BannerImages',
'BannerImage',
'BannerImage',

array(
'URL' => 'URL'
),
'getCMSFields_forPopup'
);

$idom->setUploadFolder("BannerImages");

$fields->addFieldToTab("Root.Content.Image", $idom);

return $fields;
}

_config.php
-----------------------------------------------------

And i added this to the config file

SortableDataObject::add_sortable_many_many_relation('Page', 'BannerImage');

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 February 2011 at 4:44pm

I think the second argument is the relation name..

SortableDataObject::add_sortable_many_many_relation('Page', 'BannerImages');

Go to Top