【发布时间】:2015-08-30 15:18:54
【问题描述】:
plugin.tx_xxx {
setting {
storagePid = 23
}
}
我想要实用程序文件中的这个 TYPO3 设置。 请帮帮我。
【问题讨论】:
plugin.tx_xxx {
setting {
storagePid = 23
}
}
我想要实用程序文件中的这个 TYPO3 设置。 请帮帮我。
【问题讨论】:
上述方法仅适用于控制器或服务类尝试下面它将适用于扩展中的任何PHP文件。
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Extbase\\Object\\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$extbaseFrameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$storagePid = $extbaseFrameworkConfiguration['plugin.']['tx_guesthouse_guesthouse.']['settings.']['storagePid'];
【讨论】:
你也可以只加载CONFIGURATION_TYPE_SETTINGS:
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Extbase\\Object\\
ObjectManager');
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$pluginSettings = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, null, 'tx_guesthouse_guesthouse');
$storagePid = $pluginSettings['storagePid'];
恕我直言,这更有效,因为它不会加载整个 TS 树。
【讨论】:
在包括 10 在内的任何 TYPO3 版本中,都可以使用这个单行:
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_xxxx.']['settings.']['storagePid'];
要消除点,请使用 TypoScriptService,因此
$typoScriptService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
$typoScriptSettingsWithoutDots = $typoScriptService->convertTypoScriptArrayToPlainArray($GLOBALS['TSFE']->tmpl->setup);
$storagePid = typoScriptSettingsWithoutDots['plugin']['tx_xxxx']['settings']['storagePid'];
享受吧。
【讨论】:
现在,在 Typo3 8.X 中,currentPageId 是受保护的,所以我们不能直接设置它,核心类中也不会定义任何 set 方法。以下是可能对您有所帮助的新版本的正确代码。感谢您提供正确的方向。
$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($configurationManager);
$configurationManager->getDefaultBackendStoragePid();
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
//Following will be resultant array, find your required stuff from it
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($extbaseFrameworkConfiguration);
【讨论】:
仅适用于 TYPO3 后端
获取配置前的多域设置root
$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
$configurationManager->currentPageId = ROOT_PID_OF_YOUR_DOMAIN;
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
//Following will be resultant array, find your required stuff from it
print_r($extbaseFrameworkConfiguration);
注意:不要忘记用
\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager扩展你的类 为了获得对其受保护变量的访问权限
【讨论】:
您可以在控制器中添加以下行。
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$setting = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
$ts_config = $setting['plugin.']['tx_xxxx.']['settings.']['storagePid'];
我认为它会对你有所帮助。您也可以在服务文件中使用此typo3 设置。
【讨论】:
$settings = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);,你不需要完整的TS。