2014-10-01 67 views
7

我有一个带有列表和显示操作的扩展。目前,这个扩展可以出现在多个网页:RealURL:从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']); 
} 

现在我得到这样的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参数。

+0

它需要另一种方法,它是你的扩展?你能改变它的代码吗?告诉我你如何建立你的链接/网址 – biesior 2014-10-01 14:37:32

+0

@biesior是的,这是我自己的扩展和是的,我可以改变一切。链接是这样构建的:' show article' – lampshade 2014-10-01 14:57:56

回答

5

你不能避免使用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行动,如果给定的PARAM存在:

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

+1 - 像魅力一样工作。非常感谢。我稍微改了一些代码,使其更具多功能性。我将签名更改为:'public function showAction(\ namespace $ article = null)',并将新添加的部分包含在这里:'if(!$ article){...}'。 – lampshade 2014-10-06 09:29:36

+0

我在我的扩展中使用@transient属性(请参阅http://stackoverflow.com/questions/27274477/parse-an-existing-json-string-in-fluid-template) - 它可能会失败,以上方法?当我得到它的工作时,所有“瞬态”数据不再输出 – Urs 2015-01-08 17:52:52

+0

似乎extbase对使用“动作”链接的属性类型(我已经设置错误)比现在使用替代过程更不严格。它与“瞬态”无关 – Urs 2015-01-08 19:25:49

3

签名,如果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', 
    ), 
    ), 
), 
), 
相关问题