php 使用Cronjob在后端环境中生成Typolink

5vf7fwbs  于 2022-12-10  发布在  PHP
关注(0)|答案(3)|浏览(132)

使用TYPO3 9.5,我们可以通过以下方式从Scheduler类中生成Typolink:

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$contentRenderer = $objectManager->get(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
$command = $this->linkCommand($uid, 0);
$uri = $contentRenderer->typoLink_URL($command);
return $uri;

对于TYPO3 v10,通过Cronjob调用时,相同的代码不再工作。
当从后端手动运行任务时,这段代码可以很好地工作,并基于页面uid生成URL。但是当通过Cronjob运行时,会生成以下输出:
The parsedUri "http:///www/sites/webXXXX/html/typo3/sysext/core/bin/typo3" appears to be malformed
我尝试了多种方法生成链接,但它们都以相同的错误信息结束。我不确定Cronjob在这里尝试了什么,因为上面的parsedUri看起来完全错误。
有人在使用Cronjobs和TYPO3 v10时遇到过类似的问题吗?是这个服务器相关的,还是我可以通过PHP修复的?我真的不知道这个问题的原因。

qxsslcnc

qxsslcnc1#

我来给予(未经测试):

$t3Urn = 't3://page?uid=500#5996';

// LinkService to get typolink configuration from t3://...
$typolinkConfig = GeneralUtility::makeInstance(
  \TYPO3\CMS\Core\LinkHandling\LinkService::class
)->$linkService->resolve($t3Urn);

// Absolute (if needed). Make sure that Site config contains a full base for the 
// requested page rootline AND that this base is also active in your cron environment.
// If you use application context to resolve bases, add it to the scheduler env:
// TYPO3_CONTEXT=Production/MySubcontext …/vendor/bin/typo3 scheduler:run
$typolinkConfig['forceAbsoluteUrl'] = true;

return GeneralUtility::makeInstance(
  \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class
)->typoLink_URL($typolinkConfig);
y53ybaqx

y53ybaqx2#

这个工作为我在TYPO3 11中使用的一个中间件。

public function getLink($t3Urn)
    {
//        $t3Urn = 't3://page?uid=500#5996';
        return GeneralUtility::makeInstance(
            \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class
        )->typoLink_URL(['parameter'=>$t3Urn]);
    }
z4bn682m

z4bn682m3#

//config

        //uid from the page
        $typolinkConfig['parameter'] = $pid;
        //if you want an absolute url. Can work only when the site configuration in the module Sites has a full domain as entry point
        $typolinkConfig['forceAbsoluteUrl'] = true;
        //generate url over cObject. The
        //optional add specific language uid parameter, without default is used
        //$typolinkConfig['language'] = $uidFromNeededLanguage
        $url = GeneralUtility::makeInstance(ContentObjectRenderer::class)->typoLink_URL($typolinkConfig);

相关问题