我希望我的新闻文章网址具有以下形式:http://domain.com/news/news-title-for-seo-and-usability-324/
我只希望在解码中使用新闻ID,并且仅为SEO目的添加标题。
我如何用RealURL,CoolURI或其他任何东西来完成它?
编辑:到目前为止,我设法用以下两个userfuncs做我想要的事情:
array(
'GETvar' => 'tx_news_pi1[news]',
'userFunc' => 'EXT:speciality/Classes/Hooks/RealUrlUserFunc.php:&Tx_Speciality_Hooks_RealUrlUserFunc->main',
'lookUpTable_fake' => array(
'table' => 'tx_news_domain_model_news',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND NOT deleted AND NOT hidden',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
'encodeTitle_userProc' => 'EXT:speciality/Classes/Hooks/RealUrlUserFunc.php:&Tx_Speciality_Hooks_RealUrlUserFunc->user_newsid',
),
),
),
userfuncs:
class Tx_Speciality_Hooks_RealUrlUserFunc {
public function main(array $params, $parent) {
$this->pObj = $parent;
if($params['decodeAlias']) {
return $this->alias2id($params);
} else {
return $this->id2alias($params);
}
}
function alias2id($params){
return array_pop(explode('-', $params['value']));
}
function id2alias($params){
return $this->pObj->lookUpTranslation($params['setup']['lookUpTable_fake'], $params['value'], FALSE);
}
function user_newsid($params) {
if($params['pObj']->orig_paramKeyValues['tx_news_pi1[news]'])
return $params['processedTitle'] ."-". $params['pObj']->orig_paramKeyValues['tx_news_pi1[news]'];
else
return $params['processedTitle'];
}
}
到目前为止唯一的问题是lookUpTranslation是一个受保护的函数,所以我不得不临时破解Realurl来公开这个功能。
那么如何以正确的方式从我的userfunc编码标题?
答案 0 :(得分:2)
也许有一种更简单的方法可以做到这一点,但是使用钩子确实可以使用RealUrl。关键字是“encodeTitle_userProc”,请看这里: http://docs.typo3.org/typo3cms/extensions/realurl/1.12.7/Realurl/ClasstxRealurlAdvancedphp/Configuration/Index.html?highlight=encodetitle_userproc
以下是从网址中删除已注册广告的简单示例:
RealUrlConfig:
'product' => array(
array(
'GETvar' => 'tx_myextension[product]',
'lookUpTable' => array(
....
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
'encodeTitle_userProc' => 'EXT:tx_myextension/Classes/Hooks/RealUrlUserFunc.php:&Tx_Myextension_Hooks_RealUrlUserFunc->user_productsTitle',
),
...
),
),
),
钩子类:
class Tx_Myextension_Hooks_RealUrlUserFunc {
function user_productsTitle($params) {
return preg_replace('/[R]{1}/', '', $params['processedTitle']);
}
}