Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Adding ImageField to CompositeField

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1718 Views
  • Vladas
    Avatar
    Community Member
    17 Posts

    Adding ImageField to CompositeField Link to this post

    Hello,
    I'm trying to have a two column layout where there would be editable title, editable HTMLText content and also a possibility to add an one image.

    This is the way I'm trying to do:

    <?php
    /**
    * Defines the ArticlePage page type
    */
    class HomePage extends Page {
       static $db = array(

          'ContentColumns' => 'HTMLText'

       );

    static $has_one = array(

    );

    function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $multiColumnField = new CompositeField(
             new CompositeField(
                new TextField('Header1', 'Title'),
                new HTMLEditorField('Content1', 'Content'),
                new ImageField('ColumnImage1', 'Image')
             ),
             new CompositeField(
                new TextField('Header2', 'Title'),
                new HTMLEditorField('Content2', 'Content'),
                new ImageField('ColumnImage2', 'Image')
             )
          );
          $multiColumnField->setColumnCount(2);
          
          $fields->addFieldToTab('Root.Content.Main', $multiColumnField, 'Content');
       
          
          return $fields;
       }

    }

    class HomePage_Controller extends Page_Controller {
       
    }

    ?>

    When I try to upload an image, it just doesn't show up. Could it be that the data type I'm trying to set is HTMLText? Any suggestions?

    Thank You in advance!

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Adding ImageField to CompositeField Link to this post

    I'm not sure if a composite field will do what you're looking for, but I've never used it.

    What I can see is that you haven't defined DataBase fields and relations for any of your content. You need to write Header 1, Content1, ColumnImage1, Header2, Content2, and ColumnImage2 somewhere.

    static $db = array ('header1' => 'Text', 'Content1' => 'HTMLText','header2' => 'Text', 'Content2' => 'HTMLText');
    static $has_one = array ('Image' => "Image');

    And I should warn you the I think the CMS still only supports one Image Object per page.

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