繁体   English   中英

RealURL:从URL中删除Controller和Action

[英]RealURL: Remove Controller and Action from URL

我有一个列表和显示操作的扩展名。 目前此扩展程序可以显示在多个页面上:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM