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 i can't get this to work...


Go to End


18 Posts   3625 Views

Avatar
zim

Community Member, 135 Posts

17 October 2009 at 9:38am

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.

Avatar
zim

Community Member, 135 Posts

17 October 2009 at 10:46am

I have solved the problem :)

Avatar
zim

Community Member, 135 Posts

18 October 2009 at 3:33am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 October 2009 at 5:21am

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.

Avatar
zim

Community Member, 135 Posts

18 October 2009 at 10:36am

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 :(

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 October 2009 at 11:06am

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'
);

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 October 2009 at 11:08am

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.

Avatar
zim

Community Member, 135 Posts

18 October 2009 at 11:31am

Thanks for advice I guesss I hould start again

Go to Top