RealURL:从URL中删除控制器和操作 [英] RealURL: Remove Controller and Action from URL

查看:153
本文介绍了RealURL:从URL中删除控制器和操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an extension with a list and show action. Currently this extension can appear on multiple pages:

/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 */

如何摆脱动作和控制器?

How do I get rid of the action and controller?

如果我删除:

array('GETvar' => 'tx_extension_plugin[action]'),
array('GETvar' => 'tx_extension_plugin[controller]'),

它将参数附加到URL.

it appends the parameters to the URL.

推荐答案

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

You can't avoid adding all the stuff when using f:link.action VH, instead you need to use f:link.page and pass only required params, sample:

<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操作:

next in your first action of plugin (probably list) you just need to forward request to show action if given param exists:

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...
}

这篇关于RealURL:从URL中删除控制器和操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆