简体   繁体   English

TYPO3缓存行为与更新的模型

[英]TYPO3 cache behaviour with updated models

I have this weird behaviour from Typo3 6.2 LTS. 我有Typo3 6.2 LTS的这种奇怪行为。 In my extension I have a Model with a FileReference Property. 在我的扩展程序中,我有一个带有FileReference属性的模型。 This property has a vaule != 0 . 此属性的vaule != 0 This value does exist in sys_file_reference table. sys_file_reference表中确实存在此值。

Not the weird magic happens. 不会发生奇怪的魔术。 If I try to access this file, I do only get a null value instead of a FileReference- / FileObject. 如果尝试访问此文件,则只会得到一个null值,而不是FileReference- / FileObject。

We already cleared our cache (server and browser) but nothing. 我们已经清除了缓存(服务器和浏览器),但是什么也没有。 It's still null . 它仍然为null

I appreciate every kind of help! 我感谢各种帮助!

Greetz, Paddaels Paddaels格蕾兹

I remember it was always hard to make a 1:1 relation from a domain model to a FileReference. 我记得从域模型到FileReference总是很难建立1:1关系。 I suggest you to use existing patterns and work with a ObjectStorage for that purpose. 我建议您使用现有的模式并为此目的使用ObjectStorage。

You can copy the neccessary TCA from the existing tca of the tt_content table (field image for example). 您可以从tt_content表的现有tca中复制必要的TCA(例如,字段图像)。 The Property annotation should look like: 属性注释应如下所示:

/**
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\FileReference>
 * @lazy
 * @cascade remove
 */
 protected $propName;

Of course you have to create the FileReference Model in your own namespace. 当然,您必须在自己的名称空间中创建FileReference模型。 But you can extend the Extbase basemodel, so you dont have to write any methods. 但是您可以扩展Extbase基本模型,因此您不必编写任何方法。

To map your model to the sys_file_reference table you have to add some typoscript. 要将模型映射到sys_file_reference表,您必须添加一些输入文字。

For that purpose create a ext_typoscript_setup.txt in your extensions folder and insert the following code (adjust namespace and modelname) 为此,在扩展文件夹中创建ext_typoscript_setup.txt并插入以下代码(调整名称空间和模型名称)

config.tx_extbase.persistence.classes {
    Vendor\Extension\Domain\Model\FileReference.mapping {
        tableName = sys_file_reference
    }
}

After clearing the caches in the install tool (and making database migrations of course) it should work. 清除安装工具中的缓存后(当然要进行数据库迁移),它应该可以工作。

Explanations: 说明:

@lazy: Typo3 wont fetch all references at once, only if the property is accessed. @lazy:只有访问属性后,Typo3才会立即获取所有引用。

@cascade remove: Extbase will delete all sys_file_reference records related to your domain model once the model is deleted. @cascade remove:删除模型后,Extbase将删除与您的域模型相关的所有sys_file_reference记录。

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

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