Typo3 RealURL:从URL中删除控制器和操作

Typo3 RealURL:从URL中删除控制器和操作,typo3,extbase,realurl,Typo3,Extbase,Realurl,我有一个带有列表和显示操作的扩展名。当前,此扩展可以出现在多个页面上: /page-1/ /page-2/subpage/ 我已经这样配置了realurl: $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']=array ( 'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'), 'decodeSpURL_preProc' => array('user

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

/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']);
}
现在我得到了如下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>

接下来,在插件的第一个操作(可能是
列表
)中,如果给定参数存在,您只需将请求转发到
显示
操作:

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',
      ),
    ),
  ),
),

它需要另一种方法,是您的扩展吗?你能改一下密码吗?告诉我你如何建立你的链接/urls@biesior是的,这是我自己的扩展,是的,我可以改变一切。链接是这样构建的:
show article
+1-效果很好。谢谢。我对代码做了一些修改,使它更通用。我将签名更改为:
public function showAction(\namespace$article=null)
,并将新添加的部分包装成:
if(!$article){…}
。我在扩展中使用了@transient属性(请参阅)-是否使用上述方法失败?当我让它工作时,所有的“瞬态”数据都不再输出,似乎extbase在使用“action”链接时对属性类型(我设置错误)的要求比现在的替代过程要低。这与“暂时性”无关,这个解决方案非常有效。非常感谢,在某些情况下,最好使用标准的get变量,比如tx_yourext['article'],这个答案可能会违反域驱动设计和关注点分离的方面。每个动作都应使用一致且有效的参数集直接调用-这是请求处理程序的工作,而不是任何控制器逻辑的工作。通过传递请求/响应分离并直接获取GET参数是另一种违规行为,并且在处理未经验证的用户提交的数据(SQLi、XSS等)方面是危险的。即使它能工作,它仍然是黑的。。。
# if enabled, default controller and/or action is skipped when creating URIs through the URI Builder 
plugin.tx_extension.features.skipDefaultArguments = 1
'postVarSets' => array(
  '_DEFAULT' => array(
    'extbaseParameters' => array(
      array(
        'GETvar' => 'tx_extension_plugin[action]',
        'noMatch' => 'bypass',
      ),
    ),
  ),
),