I am trying to manage multiple files with one page.
This is what I have so far:
class ProductPage extends Page {
static $db = array(
);
static $has_one = array(
'RootFolder' => 'Folder'
);
static $has_many = array(
'ProductDownloads' => 'ProductDownload',
);
function getCMSFields() {
$fields = parent::getCMSFields();
$downloadtable = new ComplexTableField(
$this,
'ProductDownloads', // relation name
'ProductDownload', // object class
ProductDownload::$field_names, // fields to show in table
ProductDownload::getCMSFields_forPopup(), // form that pops up for edit
"ProductPageID = {$this->ID}", // a filter to only display item associated with this page
"Position ASC" // Sort by name
);
$fields->addFieldToTab('Root.Content.Downloads', $downloadtable);
return $fields;
}
}
class ProductDownload extends DataObject {
static $db = array(
'Title' => 'Text',
'Position' => 'Int',
);
static $has_one = array(
'File' => 'File',
'ProductPage' => 'ProductPage',
'RootFolder' => 'Folder'
);
static $field_names = array(
'Title' => 'Title',
'File' => 'File',
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField('Title', 'Title'));
$folderName = $this->RootFolder()->FileName;
$folderName = str_replace('assets/','',$folderName);
$fields->push(new FileField("File", "File", null, null, null, $folderName));
$fields->push(new TextField('Position', 'Position'));
return $fields;
}
}
I get the following error after uploading a new file:
Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File' IN POST /admin/EditForm/field/ProductDownloads Line 724 in /public_html/sapphire/core/Object.php
Any ideas?