大家好,
我正在尝试使用此代码向我的上传字段添加 1 个以上的文件->
class FileDo extends File {
static $has_one = array(
'DocumentsFile' => 'DocumentsFile',
);
}
class DocumentsFile extends DataObject {
static $has_one = array(
'DocumentPageAcces1' => 'DocumentPageAcces1'
);
static $has_many = array(
'Files' => 'FileDo'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('DocumentPageAcces1ID');
return $fields;
}
public function onBeforeWrite() {
parent::onBeforeWrite();
$page = DataObject::get_one('DocumentPageAcces1');
if($page) {
$this->DocumentPageAcces1ID = $page->ID;
}
}
}
class DocumentPageAcces1 extends Page {
static $has_many = array(
'DocumentsFiles' => 'DocumentsFile',
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TextareaField('DocumentsIntro_en', "Document Introduction"));
$fields->addFieldToTab('Root.Main', new TextareaField('PublicationsIntro_en', "Publication Introduction"));
$fields->addFieldToTab('Root.FR', new TextareaField('DocumentsIntro_fr', "Document Introduction"));
$fields->addFieldToTab('Root.FR', new TextareaField('PublicationsIntro_fr', "Publication Introduction"));
$fields->addFieldToTab('Root.NL', new TextareaField('DocumentsIntro_nl', "Document Introduction"));
$fields->addFieldToTab('Root.NL', new TextareaField('PublicationsIntro_nl', "Publication Introduction"));
$upload = new UploadField(
'DocumentsFile',
'Document',
$this->DocumentsFiles()
);
$fields->addFieldToTab('Root.DocumentsFile', $upload);
$fields->removeByName('Content');
$fields->removeByName('Metadata');
return $fields;
}
}
class DocumentPageAcces1_Controller extends Page_Controller {
}
所以说清楚:我正在尝试在我的 DocumentPageAcces1 中添加一些 DocumentFile。当我执行此代码时,我的 DocumentPageAcces1 中有 DocumentsFiles 选项卡,在此选项卡中我有上传字段。
问题是上传字段不想保留我的文件,所以当我选择一些文件时,我在查找器中单击“确定”,没有任何反应......有人可以帮我吗?
谢谢托马斯。