简体   繁体   English

tt_content中图像的TYPO3数据库关系

[英]TYPO3 database relationship for images in tt_content

I am currently developing an extension for TYPO3. 我目前正在开发TYPO3的扩展程序。 For this purpose, I need to write a MySQL query to get the paths of uploaded images out of the database. 为此,我需要编写一个MySQL查询来从数据库中获取上载图像的路径。

My question: the table tt_contents offers a field images . 我的问题:表tt_contents提供了一个字段图像 But this field only contains the amount of images referenced - not their UIDs. 但是此字段仅包含引用的图像数量,而不包含其UID。 Image paths can be found in the table sys_file , but I can't see a way to connect these two tables. 可以在表sys_file中找到图像路径,但是我看不到连接这两个表的方法。

How can I create a relationship between the elements of tt_contents and the embedded images from sys_file ? 如何创建tt_contentssys_file元素和嵌入式图像之间的关系? How are these seemingly unconnected tables connected? 这些看似未连接的表如何连接?

Here is a small snippet I use to get uploaded images from a content object (tt_content). 这是一个小片段,用于从内容对象(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;
}

Hope that helps understand the relation between tt_content, sys_file_reference and sys_file: 希望有助于理解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

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

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