简体   繁体   English

TYPO3 FileReference 不会将表名保存在 DB 上。 从 TYPO3 上的前端上传文件

[英]TYPO3 FileReference does not save the tablename on the DB. Uploading file from frontend on TYPO3

In my custom extension on TYPO3 10.4 I'm trying to upload a file (image) from the frontend.在 TYPO3 10.4 上的自定义扩展中,我正在尝试从前端上传文件(图像)。 The file gets uploaded just fine, the rows on the DB seemed to be inserted just fine but there is some data missing.文件上传得很好,数据库上的行似乎插入得很好,但是缺少一些数据。

This is my form:这是我的表格:

    <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>

The model: model:

     /**
     * 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;
    }

The controller: controller:

     /**
     * 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);
    }

Surprisingly, just that easy, this seems to work just fine.令人惊讶的是,就这么简单,这似乎工作得很好。 I get the image uploaded on the server, the correct UID of that sys_file_reference on my custom table, the sys_file_reference gets the correct UID of that sys_file... but as you can see in the pic that follows there are a few data missing, "tablename" and "table_local" and as soon as I add that data manually the relationships work (the first rows, where this data is not missing is from rows created from the backend, working fine)我将图像上传到服务器上,我的自定义表上那个 sys_file_reference 的正确 UID,sys_file_reference 得到那个 sys_file 的正确 UID...但是正如您在下面的图片中看到的那样,缺少一些数据,“ tablename”和“table_local”,一旦我手动添加该数据,关系就会起作用(第一行,其中没有丢失此数据,来自后端创建的行,工作正常)

在此处输入图像描述

My question is, why?我的问题是,为什么? What do I do to fix that?我该怎么做才能解决这个问题?

The problem is that extbase doesn't know those values, therefore you need to state those in the TCA.问题是 extbase 不知道这些值,因此您需要 state 那些在 TCA 中。 Given this example鉴于这个例子

'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']
    ),
],

The foreign_match_fields part is the relevant one which is not needed if you don't handle file uploads in the Frontend. foreign_match_fields部分是相关的,如果您不在前端处理文件上传,则不需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM