Jump to:

7935 Posts in 1536 Topics by 943 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 484 Views
  • moonchild100
    Avatar
    Community Member
    18 Posts

    [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

    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 %>

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

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

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

  • moonchild100
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

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

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

    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 {

    }

  • moonchild100
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

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

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

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

  • moonchild100
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Image tab doesn't work with the class extends from Image Link to this post

    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?

    484 Views
Page: 1
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.