Migration 如何在TYPO3 v10中访问$GLOBALS[';TSFE';]

Migration 如何在TYPO3 v10中访问$GLOBALS[';TSFE';],migration,typo3,changelog,typo3-10.x,Migration,Typo3,Changelog,Typo3 10.x,以下代码段在版本8和9的插件中起作用 基本上,这是用来从根模板获取打字脚本设置的 protected function getTypoScriptSetup() { /** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageRepository */ $pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\

以下代码段在版本8和9的插件中起作用

基本上,这是用来从根模板获取打字脚本设置的

 protected function getTypoScriptSetup()
    {
        

        /** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageRepository */

        $pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
        $pageRepository->init(false);

        /** @var \TYPO3\CMS\Core\TypoScript\TemplateService $templateService */

        $templateService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
        $typo3Branch = class_exists(\TYPO3\CMS\Core\Information\Typo3Version::class)
            ? (new \TYPO3\CMS\Core\Information\Typo3Version())->getBranch()
            : TYPO3_branch;

        if (version_compare($typo3Branch, '9.0', '<')) {
            $templateService->init();
        }

        $templateService->tt_track = false;

        $currentPage = $GLOBALS['TSFE']->id;

        if ($currentPage === null) {
            // root page is not yet populated
            $localTSFE = clone $GLOBALS['TSFE'];

        if (version_compare($typo3Branch, '9.5', '>=')) {
                $localTSFE->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
            }
            $localTSFE->determineId();
            $currentPage = $localTSFE->id;
        }

        if (version_compare($typo3Branch, '9.5', '>=')) {
            $rootLine = GeneralUtility::makeInstance(RootlineUtility::class, (int)$currentPage)->get();
        } else {
            $rootLine = $pageRepository->getRootLine((int)$currentPage);
        }
        $templateService->start($rootLine);

        $setup = $templateService->setup;
        return $setup;
    }

受保护函数gettypostriptsetup()
{
/**@var\TYPO3\CMS\Frontend\Page\PageRepository$PageRepository*/
$pageRepository=GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\pageRepository::class);
$pageRepository->init(false);
/**@var\TYPO3\CMS\Core\TypoScript\TemplateService$TemplateService*/
$templateService=GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\templateService::class);
$typo3Branch=class\u存在(\TYPO3\CMS\Core\Information\Typo3Version::class)
?(新建\TYPO3\CMS\Core\Information\Typo3Version())->getBranch()
:3_分行;
如果(版本比较($typo3Branch,'9.0','=')){
$localTSFE->fe_user=GeneralUtility::makeInstance(FrontendUserAuthentication::class);
}
$localTSFE->determineId();
$currentPage=$localTSFE->id;
}
如果(版本比较($typo3Branch,'9.5','>=')){
$rootLine=GeneralUtility::makeInstance(RootlineUtility::class,(int)$currentPage)->get();
}否则{
$rootLine=$pageRepository->getRootLine((int)$currentPage);
}
$templateService->start($rootLine);
$setup=$templateService->setup;
返回$setup;
}
我已经坚持了好几天,运气不好。 在10.4版本中,我在clone$GLOBAL['TSFE']处收到一条错误消息

错误:“\在非对象上克隆”


我需要获取currentpage信息才能从模板中成功获取打字脚本设置。任何其他实现这一点的方法都是受欢迎的。我想我在v10变更日志中遗漏了一些内容。

使用上下文API而不是
$GLOBALS['TSFE']

由于您没有说明哪些数据对您很重要,因此无法提供进一步的帮助。

更具体一些会使其他人更有帮助。

使用上下文API而不是
$GLOBALS['TSFE']

由于您没有说明哪些数据对您很重要,因此无法提供进一步的帮助。

更具体一些会让其他人更有帮助。

谢谢你的回复。我需要访问当前的页面id,但在上下文api文档中找不到任何这样的字段。我已经看到了您更具体的内容,哪些内容可以得到更好的答案。但是我认为你还需要提供更多的信息(在第一次访问
$GLOBALS['TSFE']->id
之前提供更多的代码),因为鲁迪要求forThanks回答。我需要访问当前的页面id,但在上下文api文档中找不到任何这样的字段。我已经看到了您更具体的内容,哪些内容可以得到更好的答案。但是我认为你还需要提供更多的信息(在第一次访问
$GLOBALS['TSFE']->id
之前提供更多的代码),正如鲁迪所要求的那样,了解你所处的环境通常是有帮助的,例如Extbase controller等。了解你所处的环境通常是有帮助的,例如Extbase controller等。