Ok, that made the error go away-- thanks! Now ONE more problem: the Images do not appear to be saving to the database. In other words, in the popup, I upload the image, click save, and then when I close the popup nothing has been added to the list.
Here is my code once again:
ProjectPage
------------
class ProjectPage extends Page {
static $db = array(
'ProjectChallenge' => 'Text'
,'ProjectSolution' => 'Text'
,'ProjectResults' => 'Text'
,'ImageMainTitle' => 'Text'
);
static $has_one = array(
'ImageMain' => 'Image',
'ThumbnailMain' => 'Image'
);
static $has_many = array(
'ImageAttachments' => 'ImageAttachment'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TextAreaField('ProjectChallenge', 'The Challenge'), 'Content');
$fields->addFieldToTab("Root.Content.Main", new TextAreaField('ProjectSolution', 'The Solution'), 'Content');
$fields->addFieldToTab("Root.Content.Main", new TextAreaField('ProjectResults', 'The Results'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new ImageField('ImageMain', 'Main Image'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new ImageField('ThumbnailMain', 'Main Thumbnail'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('ImageMainTitle', 'Main Image Title'), 'Content');
$fields->removeFieldFromTab("Root.Content.Main","Content");
$imagetable = new ComplexTableField(
$this,
'ImageAttachments', // relation name
'ImageAttachment', // object class
ImageAttachment::$field_names, // fields to show in table
ImageAttachment::getCMSFields_forPopup(), // form that pops up for edit
"ImageID = {$this->ID}", // a filter to only display item associated with this page
"Name ASC" // Sort by name
);
$fields->addFieldToTab('Root.Content.ImageAttachments', $imagetable);
return $fields;
}
}
------------------
ImageAttachment
------------------
<?php
class ImageAttachment extends DataObject {
static $db = array(
'Title' => 'Text'
);
static $has_one = array(
'Image' => 'Image',
'ProjectPage' => 'ProjectPage'
);
static $field_names = array(
'Image' => 'Image',
'Title' => 'Title'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField('Title', 'Title'));
$fields->push(new ImageField('Image', 'Image'));
return $fields;
}
}
?>