解析一個新的文件將是掛接到uploadfield保存方法的最佳途徑,爲FileIframeField你可以做,按分分級,並覆蓋保存()
(在SilverStripe 3有一個名爲UploadField新的類,在UploadField你需要覆蓋UploadField->upload(SS_HTTPRequest $request)
,文件會有accesable這樣的:$tmpfile = $request->postVar($this->getName());
)
下方,例如在如何做到這一點的FileIframeField:
class myFileIFrameField extends FileIFrameField {
public function save($data, $form) {
if (
!isset($data['FileSource'])
|| ($data['FileSource'] == 'new' && (!isset($_FILES['Upload']) || !$_FILES['Upload']))
|| ($data['FileSource'] == 'existing' && (!isset($data['ExistingFile']) || !$data['ExistingFile']))
) {
$form->sessionMessage(_t('FileIFrameField.NOSOURCE', 'Please select a source file to attach'), 'required');
Director::redirectBack();
return;
}
$fileContent = false;
if($data['FileSource'] == 'new') {
$fileContent = file_get_contents($_FILES['Upload']['tmp_name']);
}
elseif($data['FileSource'] == 'existing') {
$fileObject = DataObject::get_by_id('File', $data['ExistingFile']);
$fileContent = file_get_contents($fileObject->getFullPath());
}
if ($fileContent) {
// parse the $fileContent here
}
// if you want to still save the file into a relation,
//meaning if you want to have the actually FileIframeField behaviour still in tact then call
return parent::save($data, $form);
// other wise, if you do not want to save the relation and you don't want to save the file to the server
// thenn do NOT call parent::save, just do:
// Director::redirectBack();
}
}
所以你在談論一個sitetree對象,或一個普通的數據對象,通過complextablefield進行管理?行爲是不同的,我認爲,因爲'網頁'被立即保存到分支機構 – schellmax
編號的數據庫。對不起,我遺漏了大量的信息。我正在使用DataObjectManager,並且其中的一個DataObjecta具有此上傳字段。 – MillyMonster
你能否更詳細地描述你想要用這個文件做什麼,我看不到你要做什麼,所以很難說它在哪裏做。 – Zauberfisch