Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager i can't get this to work...

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 2187 Views
  • zim
    Avatar
    Community Member
    135 Posts

    ImageDataObjectManager i can't get this to work... Link to this post

    I have got FileDataObjectManager working.. and as the tutorial says

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

    so i repeated exactly what i did for the FileDataObjectManager

    and changed to this

    <?php

    class ResourceImagesPage extends Page
    {
       static $has_many = array (
          'ResourceImages' => 'ResourceImage'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'ResourceImages', // Source name
             'ResourceImage', // 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.ResourceImages",$manager);
    return $f;
       }

    }

    ?>

    and this

    <?php

    class ResourceImages extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
          'Description' => 'Text',
          'Category' => "Enum('Industry, Finance, Education')"
       );
       
       static $has_one = array (
          'Attachment' => 'image',
          'ResourceImagesPage' => 'ResourceImagesPage'
       );
       
       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')
          );
       }
    }

    ?>

    can anyone tell me why it does not work?

    i create page and it goes wrong.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    I have solved the problem

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    how do i actually display images on my web site now... I have created a page of type images and can upload images in CMS. how do i display them now. do i need a holder page of some kind?

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    ResourceImagesPage.ss

    <% control ResourceImages %>
    <% control Attachment %>
    $CroppedImage(100,100)
    <% end_control %>
    <% end_control %>

    or

    <% control ResourceImages %>
    <% control Attachment %>
    $SetWidth(100)
    <% end_control %>
    <% end_control %>

    or

    <% control ResourceImages %>
    $Attachment
    <% end_control %>

    This is all basic SS stuff. Make sure you read up on the tutorials in the documentation.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    Hi Thanks for response i am working my way through the tutorials.

    I am making some progress on this but I am still having trouble displaying the images on .ss page.

    I can access description, and other fields on fileDataObjectManager records but not on imageDataObjectManager.

    I think I have a problem on image upload as the images are uploaded but it says there is an error on upload and then when i go to edit those images in the imagedataobjectmanager i get this mesage...(the same error when I try to display image on .ss page)

    [User Error] Couldn't run query: SELECT `Resource`.*, `Resource`.ID, if(`Resource`.ClassName,`Resource`.ClassName,'Resource') AS RecordClassName FROM `Resource` WHERE (ParentID = '14') Unknown column 'ParentID' in 'where clause'

    Any idea why? I have been trying to do this for hours now

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    That usually means it can't find the $has_one relationship on your DataObject. Try changing this:

    static $has_one = array (
    'Attachment' => 'image',
    'ResourceImagesPage' => 'ResourceImagesPage'
    );

    to this:

    static $has_one = array (
    'ResourceImagesPage' => 'ResourceImagesPage',
    'Attachment' => 'Image'
    );

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    Actaully, something is really weird. That query is looking at the Resource table, but your object is named "ResourceImages." I'm not sure what's going on, but you've got some stuff pretty messed up.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    Thanks for advice I guesss I hould start again

    2187 Views
Page: 1 2 3
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.