根据TCA文件中的环境动态设置数据

时间:2018-01-12 16:52:55

标签: typo3

我们在客户端项目中使用external_import扩展名将数据导入其数据库。

此配置的一部分存在于相关表的TCA文件中,看起来像这样:

    'external' => [
        0 => [
            'connector' => 'csv',
            'parameters' => [
                'filename' => $extensionPath . 'fileadmin/csv_import.csv',
                'delimiter' => ",",
                'text_qualifier' => '"',
                'skip_rows' => 1,
                'encoding' => 'latin1'
            ],
            'data' => 'array',
            'referenceUid' => 'reference_uid', # unique reference contained within the external file, this is required
            'priority' => 10,
            'disabledOperations' => 'delete',
            'description' => 'Import of GEMS data for funding awarded',
            'pid' => 61, # where to import the records to, this will probably need to be stored dynamically somewhere
        ]
    ]

大部分内容与此问题无关,但我认为我会将其添加到上下文中 - 问题是最后一个值pid需要根据环境设置为不同的值

我们无法对其进行硬编码,因为不同环境下的值会有所不同,所以想知道我们是否可以通过某种方式在typo3后端定义值,并且相应地填充TCA。

谢谢。

2 个答案:

答案 0 :(得分:1)

好吧,我假设你需要后端可管理的设置,它反映了TCA文件。我有办法完成 全球扩展设置的要求。

为您的扩展创建新常量(ext_conf_template.txt)。你可以从EM管理设置(https://prnt.sc/i17sli) 代码:

# cat=basic/int; type=int; label=Parent page uid (PID) for records of myTable
myTablePID = 0

在您的TCA文件中,您可以像这样提取自定义扩展程序配置

$confArr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['myext']);
// You will get all the configuration settings here. you can access particular value with index $confArr['myTablePID']
// print_r($confArr);die();

在TCA文件的顶部添加此代码。看看我已经改变的代码。

    'external' => [
        0 => [
            'connector' => 'csv',
            'parameters' => [
                'filename' => $extensionPath . 'fileadmin/csv_import.csv',
                'delimiter' => ",",
                'text_qualifier' => '"',
                'skip_rows' => 1,
                'encoding' => 'latin1'
            ],
            'data' => 'array',
            'referenceUid' => 'reference_uid', # unique reference contained within the external file, this is required
            'priority' => 10,
            'disabledOperations' => 'delete',
            'description' => 'Import of GEMS data for funding awarded',
            'pid' => $confArr['myTablePID'], # where to import the records to, this will probably need to be stored dynamically somewhere
        ]
    ]

希望这会对你有所帮助!问候!

答案 1 :(得分:0)

安装扩展程序后,您可以使用扩展程序中的ext_conf_template.txt文件进行配置。

https://docs.typo3.org/typo3cms/CoreApiReference/ExtensionArchitecture/ConfigurationOptions/Index.html

通过这种方式,您可以在每个安装(环境)的基础上更改配置并获取此类数据

$backendConfiguration =
(bool)\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)
->get('your_extension_key', 'temporaryDirectory');

从上面的文档链接中获取的代码

相关问题