TYPO3 在运行时在控制器中编辑 $GLOBALS

问题描述 投票:0回答:1

由于 TYPO3 本身不支持后端自定义功能切换,因此我想为此构建自己的实现。 我查看了 ConfigurationManager.php,它在顶部的评论中写道: '此类仅供内部核心使用。

  • 扩展通常应使用生成的 $GLOBALS['TYPO3_CONF_VARS'] 数组,
  • 请勿尝试使用扩展程序修改 LocalConfiguration.php 中的设置。'

但是如果我现在尝试在我的操作中编辑全局变量: $GLOBALS['TYPO3_CONF_VARS']['SYS']['features'][$feature] = !$GLOBALS['TYPO3_CONF_VARS']['SYS']['features'][$feature]; 该值只会在短时间内发生变化,在我重新加载页面后,该值会再次重置。

我是否遗漏了什么,或者还有其他我可以追求的价值吗?

php typo3 backend tca
1个回答
0
投票

用这个编辑你的打字稿

plugin.tx_myextension {
    settings {
        enableFeature = 1
    }
}

你的文件.php

    $featureToggle = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_myextension.']['settings.']['enableFeature'];

// ext_localconf.php
$featureToggle = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)
    ->get('myextension')['enableFeature'];

if ($featureToggle) {
    // Your feature is enabled
} else {
    // Your feature is disabled
}
© www.soinside.com 2019 - 2024. All rights reserved.