RealURL: remove controller and action from URL

I have a list extension and a show action. Currently, this extension can appear on several pages:

/page-1/ /page-2/subpage/ 

I configured realurl as follows:

 $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']); } 

Now I get the urls, for example:

 /page-1/ /* shows list */ /page-1/Action/show/name-of-single-element /* single view */ 

I really want:

 /page-1/name-of-single-element /* single view */ 

How to get rid of action and controller?

If I remove:

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

it adds parameters to the url.

+7
typo3 extbase realurl
source share
2 answers

You cannot avoid adding all the material when using f:link.action VH, instead you need to use f:link.page and pass only the required parameters, sample:

 <f:link.page additionalParams="{article : article.uid}" class="more" title="{article.name}">show article</f:link.page> 

it will generate url like

 /current/page/?article=123 

or

 /current/page/we-added-realurl-support-for-article 

next in your first plugin action (possibly list ) you just need to send a request for the show action if this parameter exists:

 public function listAction() { if (intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('article'))>0) $this->forward('show'); // Rest of code for list action... } 

and possibly change the show signature

 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... } 
+5
source share

If URIbuilder used, you can also use the configuration:

 features.skipDefaultArguments = 1 

eg:

 # if enabled, default controller and/or action is skipped when creating URIs through the URI Builder plugin.tx_extension.features.skipDefaultArguments = 1 

I use this configuration in combination with realurl bypass

 'postVarSets' => array( '_DEFAULT' => array( 'extbaseParameters' => array( array( 'GETvar' => 'tx_extension_plugin[action]', 'noMatch' => 'bypass', ), ), ), ), 
+3
source share

All Articles