TYPO3:使用不同级别的相同postVarSets在realURL中生成多个URL

时间:2016-11-22 07:50:12

标签: typo3 typo3-6.2.x realurl

在我的TYPO3中,有多个存储器具有不同的运动活动。 一个属于地方A,另一个属于不同内容的B。 现在我想生成以下URL。

第一个是一般的,另一个是具体的。

/sport/golf
/place-a/sport/golf
/place-b/sport/golf

运动被解码为/sport-detail/controller/action/sport/

我使用了默认的lookUpTable,但是网址无法解析。

'lookUpTable' => array(
    'table' => 'tx_myext_domain_model_sport',
    'id_field' => 'uid',
    'alias_field' => "url",
    'addWhereClause' => ' AND deleted = 0 AND hidden = 0',
    'useUniqueCache' => 1,
    'languageGetVar' => 'L',
    'languageField' => 'sys_language_uid',
    'transOrigPointerField' => 'l10n_parent',
    'useUniqueCache_conf' => array(
        'strtolower' => 1,
        'spaceCharacter' => '-',
    ),
)

创建有效网址需要什么,没有所有级别的golf-1等?

2 个答案:

答案 0 :(得分:0)

我不确定你想做什么。是"放置一个"和" place-b"单独的页面或是你的ext的这些附加参数?
另外,你能提供完整的RealURL配置吗?

根据目标性能,您也可以避免使用UniqueCache ...

答案 1 :(得分:0)

最后,我写了一个满足我需求的UserFunction。在这个函数中,我从realURL扩展给定的lookuptable函数,并自己获取值。 在此期间,该模型已重新命名为活动。 我现在保存运动模型中show动作和存储pid的细节pid,这样我就可以搜索整个URL路径来查找地名并查找存储pid。有了这个地方的存储pid,我可以找到合适的活动。通过在数据库中正确查找,我可以返回有效的ID。 出于搜索引擎优化的原因,我在模型中添加了一个新的字段URL,其中包含URL路径中的字符串。在id2alias方法中,我返回具有给定ID的活动的url值。

我注意到一个行为,一旦所有参数都经过哈希处理,realURL在缓存表中找不到正确的条目,所以我不得不从cHash生成中排除活动GETvar。

$GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'] = tx_myext_activity[activity]

毕竟这是我的工作设置: - )

RealURL配置:

'GETvar' => 'tx_myext_activity[activity]',
'type' => 'user',
'languageGetVar' => 'L',
'languageField' => 'sys_language_uid',
'useUniqueCache' => 0,
'userFunc' => 'EXT:MyUserFunc.php:&MyUserFunc->main'

UserFunction现在处理URL生成。

<?php

class MyUserFunc
{
    protected $sys_language_uid;
    protected $params;
    protected $localizedStrings;

    public function main($params, $ref)
    {
        if ($params) {
            $this->params = $params;
            $dirParts = $this->params['pObj']->dirParts;

            //language
            $this->sys_language_uid = 0;

            //is realUrl in encode or decode
            if ($this->params['decodeAlias']) {
                return $this->alias2id($this->params['value']);
            } else {
                return $this->id2alias($this->params['value']);
            }
        }
    }

    /*
     * Generate URL param
     */
    protected function id2alias($value)
    {
        $sysLanguageToBuild = $this->params['pathParts'][0];

        //if not default, use l10n_parent with sysuid
        if ($sysLanguageToBuild > 0) {
            $additionalWhere = ' AND l10n_parent = ' . (int)$value;
            $additionalWhere .= ' AND sys_language_uid = ' . (int)$sysLanguageToBuild;
        } else {
            $additionalWhere = ' AND uid = ' . (int)$value;
        }

        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
            'url',
            'tx_myext_domain_model_activity',
            'deleted = 0 AND hidden = 0' . $additionalWhere
        );

        $activityRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);

        if (is_array($activityRow)) {
            return $activityRow['url'];
        }

        return 'undefined';
    }

    /**
     * Decode string to uid
     * respect activities with different pid
     *
     * @param $value
     * @return int
     */
    protected function alias2id($value)
    {
        $dirParts = $this->params['pObj']->dirParts; //get array of complete path
        $place = htmlspecialchars($this->params['pObj']->dirParts[2]); //get place

        //transform place string
        $place = strtolower($place);
        $place = preg_replace("/[^A-Za-z0-9\s-._\/]/", "", $place);
        $place = trim(preg_replace("/[\s-]+/", " ", $place));

        //Query Place
        $placeRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
            'uid, activity_storage_page',
            'tx_myext_domain_model_place',
            'deleted = 0 AND hidden = 0 AND sys_language_uid = '. $this->sys_language_uid .
            ' AND LOWER(name) = "' . $place . '"'
        );

        $placeRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($placeRes);

        //Query Activity
        if (is_array($placeRow)) {
            $additionalWhere .= " AND tx_myext_domain_model_activity.pid = '" . (int)$placeRow['activity_storage_page'] . "'";
        }

        $additionalWhere = "  AND tx_myext_domain_model_activity.sys_language_uid = " . $this->sys_language_uid;
        $additionalWhere .= " AND tx_myext_domain_model_activity.url = '" . $value . "'";
        $additionalWhere .= " AND tx_myext_domain_model_activity.pid = '" . $pid . "'";


        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
            'tx_myext_domain_model_activity.uid',
            'tx_myext_domain_model_activity',
            'deleted = 0 AND hidden = 0' . $additionalWhere
        );

        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
            return (int)$row['uid'];
        }

        //catch old URLs and return uid
        $additionalWhere = "  AND tx_myext_domain_model_activity.sys_language_uid = " . $this->sys_language_uid;
        $additionalWhere .= " AND tx_myext_domain_model_activity.name = '" . $value . "'";

        $resElse = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
            'tx_myext_domain_model_activity.uid',
            'tx_myext_domain_model_activity',
            'deleted = 0 AND hidden = 0' . $additionalWhere
        );
        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resElse)) {
            return (int)$row['uid'];
        }

        return false;
    }
}