7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [SOLVED]Image tab doesn't work with the class extends from Image
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 359 Views |
-
[SOLVED]Image tab doesn't work with the class extends from Image

26 July 2011 at 1:29pm Last edited: 30 July 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 %>
-
Re: [SOLVED]Image tab doesn't work with the class extends from Image

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 -
Re: [SOLVED]Image tab doesn't work with the class extends from Image

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....
-
Re: [SOLVED]Image tab doesn't work with the class extends from Image

30 July 2011 at 6:02am Last edited: 30 July 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 {
}
-
Re: [SOLVED]Image tab doesn't work with the class extends from Image

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~
-
Re: [SOLVED]Image tab doesn't work with the class extends from Image

30 July 2011 at 8:05am Last edited: 30 July 2011 8:07am
Looking at the code straight of the bat i notice that you have two ImageResource statements in your DOM.
-
Re: [SOLVED]Image tab doesn't work with the class extends from Image

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?
| 359 Views | ||
|
Page:
1
|
Go to Top |


