【问题标题】:TYPO3 FileReference does not save the tablename on the DB. Uploading file from frontend on TYPO3TYPO3 FileReference 不会将表名保存在数据库中。在 TYPO3 上从前端上传文件
【发布时间】:2021-06-11 08:54:12
【问题描述】:

在 TYPO3 10.4 上的自定义扩展中,我尝试从前端上传文件(图像)。文件上传得很好,数据库上的行似乎插入得很好,但有一些数据丢失。

这是我的表格:

    <f:form method="post" action="create" name="blackboard"
                              object="{blackboard}" enctype="multipart/form-data">
         <f:form.textfield placeholder="Titel*" required="true" property="title"></f:form.textfield>
         <f:form.upload property="image" name="image" />
         <f:form.submit class="btn btn-primary" value="{f:translate(key: 'submit', default: 'Absenden')}"></f:form.submit>
    </f:form>

型号:

     /**
     * image
     * 
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
     */
    protected $image = null;
     /**
     * Returns the image
     * 
     * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Sets the image
     * 
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
     * @return void
     */
    public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image)
    {
        $this->image = $image;
    }

控制器:

     /**
     * action create 
     * @param Blackboard
     */
    public function createAction(Blackboard $blackboard)
    {
        $blackboard->setPid($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['hebo_blackboards']['BlackboardsStoragePId']);
        $blackboard->setUser($GLOBALS['TSFE']->fe_user->user['uid']);
        $this->blackboardRepository->add($blackboard);
    }

令人惊讶的是,就这么简单,这似乎工作得很好。我将图像上传到服务器上,我的自定义表上那个 sys_file_reference 的正确 UID,sys_file_reference 得到那个 sys_file 的正确 UID...但是正如您在下面的图片中看到的那样,缺少一些数据,“ tablename”和“table_local”,一旦我手动添加该数据,关系就会起作用(第一行,没有丢失此数据的行来自后端创建的行,工作正常)

我的问题是,为什么?我该怎么做才能解决这个问题?

【问题讨论】:

  • 你承诺的照片仍然不见了 :)
  • 哈哈,天哪,对不起,谢谢
  • 看起来你是一个人(引自手册:docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/…)。如果您已设法存储文件,则可以在创建自己的记录后更新引用,插入表和字段名。通读示例我认为您可能会错过扩展文件引用。但由于我不需要这个,我没有经验,有更多经验的人可以给你一个完整的解决方案。
  • 谢谢,是的,我想我会手动更新这些值,看看我是否可以这样做。

标签: typo3 extbase typo3-10.x filereference


【解决方案1】:

问题在于 extbase 不知道这些值,因此您需要在 TCA 中说明这些值。给定这个例子

'extra_files' => [
    'label' => 'A file',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
        'extra_files',
        [
            'foreign_match_fields' => [
                'tablenames' => 'tx_yourtable_domain_model_fo',
                'table_local' => 'sys_file'
            ]
        ],
        $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
    ),
],

foreign_match_fields 部分是相关部分,如果您不在前端处理文件上传,则不需要。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多