简体   繁体   English

TYPO3将后端内容保存在另一个数据库中

[英]TYPO3 saving Backend content in another database

I want to store content from my Backend in another database. 我想将后端中的内容存储在另一个数据库中。

So let's say i have this in my Backend: 所以说我的后端有这个:

后端中的值要存储在另一个数据库中

How can i save the value (eg the float value in the picture) in another database? 如何将值(例如图片中的float值)保存在另一个数据库中?

The reason why i need this, is, because i have another database, which is being used for some dynamic content loaded onto my Website with PHP. 我之所以需要它,是因为我有另一个数据库,该数据库用于将一些动态内容通过PHP加载到我的网站上。

Hopefully, someone has an idea and can help me :) 希望有人有一个主意,可以为我提供帮助:)

我将使用一个挂钩来更新外部数据库,该挂钩使用如果TYPO3后端中发生的更改触发的值来更新外部数据库,或者我使用一个由CLI触发并运行所有x分钟并更改其中值的调度程序任务/命令控制器。数据库。

There are several ways to achieve that. 有几种方法可以实现这一目标。 I just assume that you want to create relations between the tt_content table of TYPO3 and some external table in a different database or even different storage engine (web-service, file-system, ...). 我只是假设您要在TYPO3的tt_content表和不同数据库甚至不同存储引擎(Web服务,文件系统等)中的某些外部表之间创建关系。

In that case you could extend the TCA of the tt_content table by an additional property, let's call it external_reference . 在这种情况下,您可以通过附加属性扩展tt_content表的TCA ,将tt_content称为external_reference The backend form then should provide an additional selector field that allows to chose entities of the external data-source. 然后,后端表单应提供一个附加的选择器字段,该字段允许选择外部数据源的实体。

The following example assumes that your extension key is called my_extension , this has to be adjusted of course to the actual naming. 下面的示例假定您的扩展密钥名为my_extension ,当然必须将其调整为实际命名。

You can do so by putting the following configuration to your extension in the folder typo3conf/ext/my_extension/Configuration/TCA/Overrides/tt_content.php : 您可以通过将以下配置放入扩展名中的文件夹typo3conf/ext/my_extension/Configuration/TCA/Overrides/tt_content.php

<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    [
        'external_reference' => [
            'exclude' => 1,
            'label' => 'External Source',
            'config' => [
                'type' => 'select',
                'items' => [
                    ['-- none --', 0]
                ],
                'itemsProcFunc' => ExternalReferenceSelection::class . '->render',
                'default' => 0,
            ]
        ],
    ]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
    'tt_content',
    'external_reference'
);

Then you have to implement the selector and the retrieval from the external source, like eg 然后,您必须实现选择器并从外部源进行检索,例如

<?php
class ExternalReferenceSelection
{
    public function render(array $parameters)
    {
        $references = ExternalReferenceRepository::instance()->findAll();
        foreach ($references as $reference) {
            $parameters['items'][] = [
                $reference->getTitle(),
                $reference->getIdentifier()
            ];
        }
    }
}

To be able to persist the selected reference, you have to extend the SQL schema of tt_content as well in typo3conf/ext/my_extension/ext_tables.sql 为了能够保留选定的引用,您还必须在typo3conf/ext/my_extension/ext_tables.sql扩展tt_content的SQL模式。

#
# Table structure for table 'tt_content'
#
CREATE TABLE tt_content (

    external_reference int(11) unsigned DEFAULT '0' NOT NULL

);

The database schema is updated by invoking the database analyzer in the TYPO3 Install Tool, or by (re-)installing the extension in the Extension Manager. 通过调用TYPO3安装工具中的数据库分析器,或通过在扩展管理器中(重新)安装扩展,可以更新数据库模式。

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

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