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

[SOLVED]Image tab doesn't work with the class extends from Image


Go to End


7 Posts   1227 Views

Avatar
moonchild100

Community Member, 18 Posts

26 July 2011 at 1:29pm

Edited: 30/07/2011 9:44am

The problem is the the ImageResouces.php cannot have controller, as long as i delete the controller class, every thing's fine....

though i did change class ImageResource extends DataObject to
class ImageResource extends Image, but I don't think this really matters....

Also, in order to display the image on the page, i cannot use
<% control Images %>
<img src="$Images.URL"/>
<% end_control%>

instead, it should be
<% control Images %>
<img src="$URL"/>
<% end_control%>

it seems doesn't recognize the expression $Images....though I saw a lot of examples online that did use $Images.URL.
Any one can explain a little about this?

Trying to get the image work, not luck now

ImageResource.php
<?php
class ImageResource extends DataObject
{
static $has_one = array (

'SectionPage' => 'SectionPage',
'ImageResource'=>'Image'

);

}

class ImageResource_Controller extends ContentController
{

}
?>
////////////////////////////////////////////////////////

SectionPage.php
class SectionPage extends Page
{
static $has_many= array (
'Images'=>'ImageResource'
);

public function getCMSFields()
{
$fields = parent::getCMSFields();

$manager = new ImageDataObjectManager(
$this,
'Images',
'ImageResource',
'ImageResource',
array('Title'=>'Title', 'Description'=>'Description'),
new FieldSet(
new TextField('Title'),
new TextareaField('Description')
));
$manager -> setAllowedFileTypes(array('jpg', 'png','gif'));
$fields->addFieldToTab("Root.Content.Images", $manager);

return $fields;
}
}

class SectionPage_Controller extends Page_Controller
{

}

?>

Also, the ImagePage.ss i'm not sure what should I put there is this right?

<% control Images%>
$ImageResource
$Title

<% end_control %>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

27 July 2011 at 1:13am

Your SectionPage class is in ImagePage.php? That's not gonna work.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
moonchild100

Community Member, 18 Posts

27 July 2011 at 4:38pm

my bad..i type the file name wrong, should be SectionHolder.php

I m sure that the class name, controller name and the php file's name are consistent...

if I just use Image type and don't create any subclass of Image class, then i can add image, but since there's no relation between image class and the page type class, all the images are showing in the CMS, but only in CMS, i cannot display the images on the website.

frustrated....

Avatar
MagicUK

Community Member, 60 Posts

30 July 2011 at 6:02am

Edited: 30/07/2011 6:02am

What Uncle cheese means is that the class name within the file has to match the name of the file

i.e in SectionHolder.php

your class should start:

class SectionHolder extends Page {

}

Avatar
moonchild100

Community Member, 18 Posts

30 July 2011 at 7:53am

Actually, the class name and the file name are the same. i just typed them wrong...it just doesn't work~

Avatar
MagicUK

Community Member, 60 Posts

30 July 2011 at 8:05am

Edited: 30/07/2011 8:07am

Looking at the code straight of the bat i notice that you have two ImageResource statements in your DOM.

Avatar
moonchild100

Community Member, 18 Posts

30 July 2011 at 8:12am

doing mean

$manager = new ImageDataObjectManager(
$this,
'Images',
'ImageResource',
'ImageResource',
array('Title'=>'Title', 'Description'=>'Description'),
new FieldSet(
new TextField('Title'),
new TextareaField('Description')
));
//////////////////////////////////

this is the definition of the constructor for imagedataobjectmanager

public function __construct($controller, $name = null, $sourceClass = null, $fileFieldName = null,.....)

shouldn't it be this way?