【问题标题】:TYPO3 database relationship for images in tt_contenttt_content 中图像的 TYPO3 数据库关系
【发布时间】:2014-02-09 11:32:27
【问题描述】:

我目前正在为 TYPO3 开发一个扩展。为此,我需要编写一个 MySQL 查询来从数据库中获取上传图片的路径。

我的问题:tt_contents 表提供了一个字段images。但是这个字段只包含引用的图像数量——而不是它们的 UID。图片路径可以在表 sys_file 中找到,但我看不到连接这两个表的方法。

如何在 tt_contents 的元素和 sys_file 的嵌入图像之间建立关系?这些看似未连接的表是如何连接的?

【问题讨论】:

    标签: mysql plugins content-management-system structure typo3


    【解决方案1】:

    这是我用来从内容对象 (tt_content) 获取上传图像的小 sn-p。

    public function getContentImages($tt_content_uid) {
        /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */
        $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\FileRepository');
        $fileObjects = $fileRepository->findByRelation('tt_content', 'image', $tt_content_uid);
    
        // Get file information
        $files = array();
        foreach ($fileObjects as $key => $value) {
            $file = array();
            $file['reference'] = $value->getReferenceProperties();
            $file['original'] = $value->getOriginalFile()->getProperties();
            $files[] = $file;
        }
    
        return $files;
    }
    

    【讨论】:

    • 非常感谢 - 这很好用!我在编写 MySQL 查询时陷入了僵局,以至于我没有想到其他方法。 findByRelation 在类似情况下肯定会有所帮助。
    【解决方案2】:

    希望对理解tt_content、sys_file_reference和sys_file之间的关系有所帮助:

        select uid from sys_file_reference where tablenames = "tt_content" and uid_foreign = 185183 and fieldname = "image";
        #>> uid = 47079
    
        SELECT * FROM `sys_file_reference` where uid = 47079;
        #>> uid_local = 16573
    
        SELECT * FROM `sys_file` where uid = 16573;
        #>> identifier = /Ordner/Products/Pictures/Bild.jpg
    
    
    
        select uid from sys_file_reference where tablenames = "tt_content" and uid_foreign = 185184 and fieldname = "image";
        #>> uid = 46868
    
        SELECT * FROM `sys_file_reference` where uid = 46868;
        #>> uid_local = 48
    
        SELECT * FROM `sys_file` where uid = 48;
        #>> identifier = /Ordner/AnderesBild.png
    
    
    
        UPDATE sys_file_reference SET uid_local = 16573 WHERE uid_local = 48 and uid = 46868;
        #>> im Content Element (CType = image) angegebenes Bild ist nun auf ein anderes umgestellt
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多