我有一个带有列表和显示操作的扩展。目前此扩展可以出现在多个页面上:
/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 */
如何摆脱动作和控制器?
如果我删除:
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>
它将生成类似
的 url/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...
}
如果使用
URIbuilder
,您还可以使用配置:
features.skipDefaultArguments = 1
例如;
# if enabled, default controller and/or action is skipped when creating URIs through the URI Builder
plugin.tx_extension.features.skipDefaultArguments = 1
我将此配置与 realurl 绕过结合使用
'postVarSets' => array(
'_DEFAULT' => array(
'extbaseParameters' => array(
array(
'GETvar' => 'tx_extension_plugin[action]',
'noMatch' => 'bypass',
),
),
),
),