如何在实用程序文件中获取 TYPO3 设置?
How to get TYPO3 settings in the utility files?
plugin.tx_xxx {
setting {
storagePid = 23
}
}
我想在实用程序文件中使用这个 TYPO3 设置。
请帮助我。
您可以在您的控制器中添加以下行。
$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 设置。
以上方法仅适用于控制器或服务class尝试下面它适用于扩展中的任何 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'];
Only for TYPO3 Backend
对于多域在获取配置之前设置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);
Note: Don't forget to extend your class with \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
in
order to obtain access for it's protected variables
现在,在Typo3 8.X中,currentPageId是受保护的,所以我们不能直接设置它,核心class中也不会定义任何设置方法。以下是可能对您有所帮助的新版本的正确代码。感谢指点。
$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版本包括10,都可以用这个单行:
$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'];
尽情享受吧。
您也可以只加载 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 树。
plugin.tx_xxx {
setting {
storagePid = 23
}
}
我想在实用程序文件中使用这个 TYPO3 设置。 请帮助我。
您可以在您的控制器中添加以下行。
$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 设置。
以上方法仅适用于控制器或服务class尝试下面它适用于扩展中的任何 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'];
Only for TYPO3 Backend
对于多域在获取配置之前设置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);
Note: Don't forget to extend your class with
\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
in order to obtain access for it's protected variables
现在,在Typo3 8.X中,currentPageId是受保护的,所以我们不能直接设置它,核心class中也不会定义任何设置方法。以下是可能对您有所帮助的新版本的正确代码。感谢指点。
$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版本包括10,都可以用这个单行:
$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'];
尽情享受吧。
您也可以只加载 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 树。