在 TYPO3 v10.4 中获取当前 pageid [英] Get current pageid in TYPO3 v10.4
问题描述
以前在版本 8 和 9 中,我可以使用以下方法访问页面 ID
Previously in version 8 and 9, I could access the page id using the following
$currentPid = $GLOBALS['TSFE']->id
$currentPid = $GLOBALS['TSFE']->id
我现在正在更新我的插件以支持 10.4,上面的代码片段给出了一个空值.如何访问页面 id,然后访问页面 id 的根.我需要根页面来从根模板收集排版信息.
I am now updating my plugin to support 10.4, the above snippet gives out a null value. How can I access the page id and then also the root of the page id. I need the root page to gather the typoscript info from the root template.
$currentPage = $GLOBALS['TSFE']->id;
if ($currentPage === null) {
$localTSFE = clone $GLOBALS['TSFE'];
if (version_compare($typo3Branch, '9.5', '>=')) {
$localTSFE->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
}
$localTSFE->determineId();
$currentPage = $localTSFE->id;
}
$rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $currentPage)->get();
$templateService->start($rootLine);
$setup = $templateService->setup;
return $setup;
在第一行之后,currentPage 被设置为 null.然后在克隆 $GLOBALS['TSFE'] 时抛出错误.
错误:_clone 在非对象上
After the first line the currentPage is being set to null.
Then an error is being thrown when cloning the $GLOBALS['TSFE'].
Error: _clone on non-object
推荐答案
试试这个.
当前页面:
$pageUid = (int)GeneralUtility::_GET('id');
获取根页面:
protected function getRootPage($pageUid) {
$page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(RootlineUtility::class, $pageUid);
$rootLines = $page->get();
if(!empty($rootLines)) {
foreach ($rootLines as $rootLine) {
if(!empty($rootLine['is_siteroot']) && $rootLine['is_siteroot']) {
return $rootLine['uid'];
}
}
}
return 0;
}
这篇关于在 TYPO3 v10.4 中获取当前 pageid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!