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.

Data Model Questions /

Adding ImageField to CompositeField


Reply


2 Posts   1881 Views

Avatar
Vladas

Community Member, 17 Posts

27 February 2010 at 3:10am

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!

Avatar
zenmonkey

Community Member, 532 Posts

27 February 2010 at 10:18am

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.