[英]Typo3 7.2 add file reference to extension model
I'm using Typo 7.2 and am looking for an answer to the following question: 我正在使用Typo 7.2,正在寻找以下问题的答案:
How to add a generated File as FileReference programmatically to an extension model? 如何以编程方式将生成的文件作为FileReference添加到扩展模型?
First some infos regarding my achievements/tries. 首先是有关我的成就/尝试的一些信息。
DONE A command controller runs over folders, looks for a specific image and creates a blurred file via GraphicFunctions. 完成命令控制器在文件夹上运行,查找特定图像,然后通过GraphicFunctions创建模糊文件。 The generated file is added to the storage as a standalone simple file and appears in the sys_file table.
生成的文件作为独立的简单文件添加到存储,并显示在sys_file表中。
$fileObject = $posterStorage->addFile(
$convertResult[3],
$posterStorage->getFolder($blurFolderName),
$newFileName);
PARTIALLY DONE. 部分完成。 Now I need to add the generated file as a file reference to my model.
现在,我需要将生成的文件添加为对模型的文件引用。 The problem is, that I'm able to do this, but only by hacking core - not acceptable - and unable to do it the right way.
问题是,我能够做到这一点,但是只能通过侵入内核来实现,这是不可接受的,并且无法以正确的方式做到这一点。 The model says:
模型说:
public function addPosterWebBlur(
\TYPO3\CMS\Extbase\Domain\Model\FileReference $posterWebBlur
) {
$this->posterWebBlur->attach($posterWebBlur);
}
So I succeeded by extending the FileReference class: 因此,我成功扩展了FileReference类:
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
public function setFile(\TYPO3\CMS\Core\Resource\File $falFile) {
$this->$uidLocal = (int)$falFile->getUid();
}
}
The reference does not get established and I just get the following error in the backend: 该参考未建立,我在后端仅得到以下错误:
Table 'db_name.tx_ext_name_domain_model_filereference' doesn't exist.
UPDATE After integrating the data from Frans in ext_typoscript_setup.txt, the model can be saved, creates an sys_file_reference entry and acts nicely in the backend. 更新将来自Frans的数据集成到ext_typoscript_setup.txt中后,可以保存模型,创建sys_file_reference条目,并且在后端运行良好。 But there are a few points open to fulfill all needs:
但是,有几点可以满足所有需求:
You have to tell the extbase persistence layer to use the correct table. 您必须告诉extbase持久层使用正确的表。 See for instance this example https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt
例如参见以下示例https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt
gr. gr。 Frans
弗兰斯
Trying to answer 1) See https://github.com/helhum/upload_example/blob/master/Configuration/TCA/tx_uploadexample_domain_model_example.php#L128 You should probably check the TCA definition for your posterWebBlur field. 尝试回答1)参见https://github.com/helhum/upload_example/blob/master/Configuration/TCA/tx_uploadexample_domain_model_example.php#L128您可能应该检查posterWebBlur字段的TCA定义。 Second param of getFileFieldTCAConfig() TT
getFileFieldTCAConfig()TT的第二个参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.