简体   繁体   English

为什么 TYPO3 调用错误的文件参考表

[英]Why TYPO3 calls a wrong File Reference table

I have a Model for a Products table with this code to get the images references:我有一个 Model 用于 Products 表,其中包含此代码以获取图像参考:

/**
 * Returns the images
 *
 * @return \TYPO3\CMS\Core\Resource\FileReference $images
 */
public function getImages() {
    $fileRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
    $this->images = $fileRepository->findByRelation('tx_myext_domain_model_products', 'images', $this->uid);
    return $this->images;
}

But it triggers an error:但它会触发一个错误:

ERROR => 'Table 'database.tx_core_resource_filereference' doesn't exist'

Don't sure why this table name is used.不知道为什么使用这个表名。 sys_file_reference is the name of the real table in the database. sys_file_reference是数据库中真实表的名称。

If this is in the domain as you suggested, then all you should need is:如果这在您建议的域中,那么您只需要:

.../Classes/Domain/Model/Product.php .../类/域/型号/产品.php

...

  /**
   * images
   *
   * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
   */
  protected $images = null;


  /**
   * Returns the images
   *
   * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference images
   */
  public function getImages()
  {
      return $this->images;
  }

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

...

Then the TCA for products would require config for images... for example:然后产品的 TCA 将需要配置图像......例如:

.../Configuration/TCA/tx_yourext_domain_model_product.php .../配置/TCA/tx_yourext_domain_model_product.php

...


        'images' => [
          'label' => 'FAL Image',
          'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'images',
            [
              'appearance' => [
                'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
              ],
              // custom configuration for displaying fields in the overlay/reference table
              // to use the image overlay palette instead of the basic overlay palette
              'overrideChildTca' => [
                'types' => [
                  '0' => [
                    'showitem' => '
                    --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                    --palette--;;filePalette'
                  ],
                  \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                    'showitem' => '
                    --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                    --palette--;;filePalette'
                  ],
                ],
              ],
            ],
            $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
          ),
        ],

...

Seems like you use a wrong FileReference .好像您使用了错误的FileReference Check if you import the correct one in your Model:检查您是否在 Model 中导入了正确的:

Wrong:错误的:

use TYPO3\CMS\Core\Resource\FileReference;

Correct:正确的:

use TYPO3\CMS\Extbase\Domain\Model\FileReference;

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

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