1

我需要在调度程序任务中创建指向前端网站的链接。我搜索并环顾四周,发现的是一个启动 TSFE 的示例脚本。之后我可以启动 tslib_cObj 来创建一些链接;我想。

但是,当我尝试使用 $cObj->typoLink_URL(1); 创建错字链接时,我得到的是递归错误。费。或任何其他允许创建错字链接的方法。

以下是我用来在 $GLOBALS 中启动 TSFE 的脚本,就像在前端的扩展中工作时一样:

<?php
function initTSFE($pageUid = 1, $overrule = FALSE) {
    // declare
    $temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');

    // begin
    if (!is_object($GLOBALS['TT']) || $overrule === TRUE) {
        $GLOBALS['TT'] = new t3lib_timeTrack;
        $GLOBALS['TT']->start();
    }

    if ((!is_object($GLOBALS['TSFE']) || $overrule === TRUE) && is_int($pageUid)) {
        // builds TSFE object
        $GLOBALS['TSFE'] = new $temp_TSFEclassName($GLOBALS['TYPO3_CONF_VARS'],
            $pageUid, $type=0, $no_cache=0, $cHash='', $jumpurl='', $MP='', $RDCT='');

        // builds rootline
        $GLOBALS['TSFE']->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
        $rootLine = $GLOBALS['TSFE']->sys_page->getRootLine($pageUid);

            // init template
        $GLOBALS['TSFE']->tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext');
        $GLOBALS['TSFE']->tmpl->tt_track = 0;// Do not log time-performance information
        $GLOBALS['TSFE']->tmpl->init();

        // this generates the constants/config + hierarchy info for the template.
        $GLOBALS['TSFE']->tmpl->runThroughTemplates($rootLine, $start_template_uid=0);
        $GLOBALS['TSFE']->tmpl->generateConfig();
        $GLOBALS['TSFE']->tmpl->loaded=1;

        // get config array and other init from pagegen
        $GLOBALS['TSFE']->getConfigArray();
        $GLOBALS['TSFE']->linkVars = ''.$GLOBALS['TSFE']->config['config']['linkVars'];

        if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc_onlyP']) {
            foreach (t3lib_div::trimExplode(',',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc_onlyP'],1) as $temp_p) {
                $GLOBALS['TSFE']->pEncAllowedParamNames[$temp_p]=1;
            }
        }

        // builds a cObj
        $GLOBALS['TSFE']->newCObj();
    }
}

我在调度程序任务中尝试执行以下操作:

<?php
public function execute() {
    $this->initTSFE();
    $cObj = t3lib_div::makeInstance('tslib_cObj');
    var_dump($cObj->getTypoLink_URL(1));exit;
}

通过调度程序执行此任务时,这向我显示了以下结果:http: //i.imgur.com/DHzys.png

非常感谢任何帮助=)

注意:getTypoLink_URL 中的 1 值在 Typo3 中确实作为页面存在。

4

1 回答 1

1

我试图使用的这个 initTSFE() 方法似乎有问题。我不确定是什么,但我发现它的另一个版本似乎确实有效:

public function initTSFE($pageUid=1) {
    require_once(PATH_tslib.'class.tslib_fe.php');
    require_once(PATH_t3lib.'class.t3lib_userauth.php');
    require_once(PATH_tslib.'class.tslib_feuserauth.php');
    require_once(PATH_t3lib.'class.t3lib_cs.php');
    require_once(PATH_tslib.'class.tslib_content.php');
    require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
    require_once(PATH_t3lib.'class.t3lib_page.php');

    $TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');

    if (!is_object($GLOBALS['TT'])) {
        $GLOBALS['TT'] = new t3lib_timeTrack;
        $GLOBALS['TT']->start();
    }

    // Create the TSFE class.
    $GLOBALS['TSFE'] = new $TSFEclassName($GLOBALS['TYPO3_CONF_VARS'],$pageUid,'0',1,'','','','');
    $GLOBALS['TSFE']->connectToMySQL();
    $GLOBALS['TSFE']->initFEuser();
    $GLOBALS['TSFE']->fetch_the_id();
    $GLOBALS['TSFE']->getPageAndRootline();
    $GLOBALS['TSFE']->initTemplate();
    $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
    $GLOBALS['TSFE']->forceTemplateParsing = 1;
    $GLOBALS['TSFE']->getConfigArray();
}

谢谢你!

于 2011-09-12T06:31:10.747 回答