gpt4 book ai didi

typo3 - RealURL:从 URL 中删除 Controller 和操作

转载 作者:行者123 更新时间:2023-12-04 10:24:48 26 4
gpt4 key购买 nike

我有一个带有列表和显示操作的扩展。目前这个扩展可以出现在多个页面上:

/page-1/
/page-2/subpage/

我已配置 realurl像那样:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']=array (
'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
'decodeSpURL_preProc' => array('user_decodeSpURL_preProc'),
'_DEFAULT' => array (

'postVarSets' => array(
'_DEFAULT' => array(
'controller' => array(
array(
'GETvar' => 'tx_extension_plugin[controller]',
'noMatch' => 'bypass',
),
),
'extension' => array(
array(
'GETvar' => 'tx_extension_plugin[action]',
),
array(
'GETvar' => 'tx_extension_plugin[controller]',
),
array(
'GETvar' => 'tx_extension_plugin[value]',
'lookUpTable' => array(
'table' => 'table',
'id_field' => 'uid',
'alias_field' => 'name',
'addWhereClause' => ' AND NOT deleted AND NOT hidden',

);

function user_decodeSpURL_preProc(&$params, &$ref) {
$params['URL'] = str_replace('page-1/', 'page-1/extension/', $params['URL']);
}

function user_encodeSpURL_postProc(&$params, &$ref) {
$params['URL'] = str_replace('page-1/extension/', 'page-1/', $params['URL']);
}

现在我得到的网址如下:
/page-1/ /* shows list */
/page-1/Action/show/name-of-single-element /* single view */

我真正想要的是:
/page-1/name-of-single-element /* single view */

如何摆脱 Action 和 Controller ?

如果我删除:
array('GETvar' => 'tx_extension_plugin[action]'),
array('GETvar' => 'tx_extension_plugin[controller]'),

它将参数附加到 URL。

最佳答案

使用 f:link.action 时,您无法避免添加所有内容VH,您需要使用 f:link.page并仅传递必需的参数,示例:

<f:link.page additionalParams="{article : article.uid}" class="more" title="{article.name}">show article</f:link.page>

它会生成像
/current/page/?article=123

或者
/current/page/we-added-realurl-support-for-article

接下来在您的插件的第一个操作(可能是 list )中,您只需要将请求转发到 show如果给定参数存在,则操作:
public function listAction() {
if (intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('article'))>0) $this->forward('show');

// Rest of code for list action...
}

并可能更改 show 的签名
public function showAction() {

$article = $this->articleRepository->findByUid(intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('article')));

if ($article == null) {
$this->redirectToUri($this->uriBuilder->reset()->setTargetPageUid($GLOBALS['TSFE']->id)->build());
}


// Rest of code for show action...
}

关于typo3 - RealURL:从 URL 中删除 Controller 和操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26142614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com