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

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


Reply

7 Posts   510 Views

Avatar
moonchild100

26 July 2011 at 1:29pm (Last edited: 30 July 2011 9:44am), Community Member, 18 Posts

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

27 July 2011 at 1:13am 4085 Posts

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

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

Avatar
moonchild100

27 July 2011 at 4:38pm Community Member, 18 Posts

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

30 July 2011 at 6:02am (Last edited: 30 July 2011 6:02am), Community Member, 60 Posts

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

30 July 2011 at 7:53am Community Member, 18 Posts

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

Avatar
MagicUK

30 July 2011 at 8:05am (Last edited: 30 July 2011 8:07am), Community Member, 60 Posts

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

Avatar
moonchild100

30 July 2011 at 8:12am Community Member, 18 Posts

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?