代码之家  ›  专栏  ›  技术社区  ›  csba

如何更新extbase中存储为字符串的图像?

  •  0
  • csba  · 技术社区  · 6 年前

    我最近创建了一个具有文件上传功能的扩展名。我决定把它储存成一根绳子。我这样用过:

        public function initializeAction() {
            if ($this->arguments->hasArgument('blog')) {
                $this->arguments->getArgument('blog')->getPropertyMappingConfiguration()->setTargetTypeForSubProperty('image', 'array');
            }
        } 
    

    在模型中:

      /**
       * Returns the image
       * 
       * @return string $image
       */
      public function getImage()
      {
            return $this->image;
      }
    
      /**
       * Sets the image
       * 
       * @param \array $image
       * @return void
       */
      public function setImage(array $image)
      {
            die(debug::var_dump($image));
            if (!empty($image['name']))
            {
                  $imageName = $image['name'];
                  $imageTempName = $image['tmp_name'];
                  $basicFileUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
                  $imageNameNew = $basicFileUtility->getUniqueName($imageName, \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('uploads/tx_myextension/'));
                  \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($imageTempName, $imageNameNew);
                  $this->image = basename($imageNameNew);
            }
      }
    

       'config' => [
            'type' => 'group',
            'internal_type' => 'file',
            'uploadfolder' => 'uploads/tx_myextension',
            'show_thumbs' => 1,
            'size' => 1,
            'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
            'disallowed' => ''
        ],
    

    以我的形式:

    <f:form action="update" name="blog" object="{blog}" >
    <f:form.upload property="image" class="form-control" />
    ...
    

    现在 但是,当我尝试更改此图像(使用updateAction)时,会收到以下错误消息:

     Exception while property mapping at property path "image":
     No converter found which can be used to convert from "string" to "array".
    

    我想避免通过FAL上传或编写自己的转换。我希望我只是错过了一些小事。

    2 回复  |  直到 6 年前
        1
  •  0
  •   René Pflamm    6 年前

    看一看 update script tt_address 查看如何进行更新。

    简而言之:您必须读取文件的所有条目,并将它们从upload dir移到文件存储中,然后必须添加 file_reference 连接 sys_file 使用域模型:

    GeneralUtility::upload_copy_move(
        PATH_site . 'uploads/tx_myextension/' . $imageName,
        PATH_site . 'fileadmin/tx_myextension/' . $imageName);
    
    $fileObject = $this->storage->getFile('fileadmin/tx_myextension/' . $imageName);
    if ($fileObject instanceof \TYPO3\CMS\Core\Resource\File) {
        $this->fileRepository->add($fileObject);
        $dataArray = [
            'uid_local' => $fileObject->getUid(),
            'tablenames' => 'tx_your_domain_model',
            'fieldname' => 'image',
            'uid_foreign' => 'your model uid',
            'table_local' => 'sys_file',
            'cruser_id' => 999,
            'pid' => 'your_model_pid',
            'sorting_foreign' => $imageCount,
            'sys_language_uid' => 0
        ];
    
        if ($this->getDatabaseConnection()->exec_INSERTquery('sys_file_reference', $dataArray)) {
            $imageCount++;
        }
    }
    
        2
  •  0
  •   csba    6 年前

    <f:form action="update" enctype="multipart/form-data" name="blog" object="{blog}" >