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

How do I get ImageDataObjectManager to work?


Go to End
Reply

14 Posts   4367 Views

Avatar
Roweena

2 October 2009 at 1:24am Community Member, 28 Posts

I've got FileDataObjectManager set up and working ok but I want to use ImageDataObjectManager. I'm following the instructions at http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager&s=imagedataobjectmanager but the instructions for ImageDataObjectManager as follows:

"The ImageDataObjectManager takes the same arguments and configuration as a FileDataObjectManager. The only difference is that its only allowed file classes are Image or subclasses thereof"

...don't mean much to me as I'm not a developer.

Can any one help with how to set this up or provide some example code?

Thanks

Avatar
UncleCheese

2 October 2009 at 1:25am 4085 Posts

Did you see the docs for FileDOM? That would be a good place to start. The only difference is that it manages images, not just generic files.

Avatar
Roweena

2 October 2009 at 1:28am Community Member, 28 Posts

Thanks for the quick reply?
Where can I find these docs?

Avatar
UncleCheese

2 October 2009 at 1:48am 4085 Posts

http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager#filedataobjectmanager

Avatar
Roweena

2 October 2009 at 1:52am Community Member, 28 Posts

I'm already looking at that, I've set up the file manager and it's working ok but I just don't know which bits of code I need to change and what I need to replace with to make the ImageDataObjectManager work?

Thanks again :-)

Avatar
UncleCheese

2 October 2009 at 3:22am 4085 Posts

It works exactly the same. Just change "FileDataObjectManager" to "ImageDataObjectManager"

e.g...

new FileDataObjectManager(
$this,
'SomeObjects',
'SomeObject',
'SomeFile',
array('Foo' => 'Foo', 'Bar' => 'Bar')
);

becomes..

new ImageDataObjectManager(
$this,
'SomeObjects',
'SomeObject',
'SomeFile',
array('Foo' => 'Foo', 'Bar' => 'Bar')
);

The only requirement is that "SomeFile" in that example is an Image or Image subclass.

Avatar
Roweena

2 October 2009 at 6:13am Community Member, 28 Posts

Thanks again for your help, I've changed the bits I think shoudl be chanegd as per yoru instructions but the resources tab is just showing blank in the cms, ie the tab is there but has nothing in it. My code is as follows, I'm sure I'm missing something:

class ResourcePage extends Page
{
   static $has_many = array (
      'Resources' => 'Resource'
   );
   
   public function getCMSFields()
   {
      $f = parent::getCMSFields();
      $manager = new ImageDataObjectManager(
         $this, // Controller
         'Resources', // Source name
         'Resource', // Source class
         'Attachment', // File name on DataObject
         array(
            'Name' => 'Name',
            'Description' => 'Description',
            'Category' => 'Category'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
$f->addFieldToTab("Root.Content.Resources",$manager);
return $f;
}

}

AND

class Resource extends DataObject
{
   static $db = array (
      'Name' => 'Text',
      'Description' => 'Text',
      'Category' => "Enum('2009, Transitional-Spaces, Brighton-Bands')"
   );
   
   static $has_one = array (
      'Attachment' => 'Image',
      'ResourcePage' => 'ResourcePage'
   );
   
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Name'),
         new TextareaField('Description'),
         new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
         new FileIFrameField('Attachment')
      );
   }
}

Avatar
Roweena

3 October 2009 at 9:22pm Community Member, 28 Posts

Ok, so following on from the above post, I've got FileDataObjectManage to work fine, but when I change the code (to the code pasted in last posted) I get a blank image/resource tab in the cms admin, where I should be seeing the image upload buttons/functions. Any ideas?

Go to Top