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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager


Go to End
Reply

10 Posts   1636 Views

Avatar
yug

22 February 2011 at 6:43pm Community Member, 17 Posts

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

23 February 2011 at 10:52am 4085 Posts

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

23 February 2011 at 12:05pm Community Member, 17 Posts

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

23 February 2011 at 12:38pm 4085 Posts

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

23 February 2011 at 1:31pm Community Member, 17 Posts

I cant seem to find anything and what is a sticky

Avatar
UncleCheese

23 February 2011 at 2:44pm 4085 Posts

Try this http://silverstripe.org/dataobjectmanager-module-forum/show/7323?start=16

Avatar
yug

23 February 2011 at 4:30pm Community Member, 17 Posts

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

23 February 2011 at 4:44pm 4085 Posts

I think the second argument is the relation name..

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

Go to Top