tt_content中图像的TYPO3数据库关系

时间:2014-01-20 10:33:30

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

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

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

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

2 个答案:

答案 0 :(得分:3)

以下是我用来从内容对象(tt_content)上传图片的小片段。

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

答案 1 :(得分:0)

希望有助于理解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