簡體   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