Extbase and RealURL

another day, another problem. Extbase is becoming main framework for TYPO3 extension, because it’s really easy to create a frontend plugin to show (listing or detail view) of a records. Since it’s MVC framework, Extbase create a complex URL for each record.


http://domain.tld/pageName/?tx_extension_plugin[action]=show&tx_extension_plugin[controller]=controllerName&tx_extension_pluginName[param]=9

how to short this?

following “standard” realurl config is normally used to encode the GET parameter to “readable” url path

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'postVarSets' => array(
  '_DEFAULT' => array(
    'urlPath' => array(
      array(
        'GETvar' => 'tx_extension_plugin[controller]',
      ),
      array(
        'GETvar' => 'tx_extension_plugin[action]',
      ),
      array(
        'GETvar' => 'tx_extension_plugin[param]',
        'lookUpTable' => array(
          'table' => 'tx_rlpjobportal_domain_model_stellenboerse',
          'id_field' => 'uid',
          'alias_field' => 'title',
          'addWhereClause' => ' AND NOT deleted',
          'useUniqueCache' => 1,
          'useUniqueCache_conf' => array(
            'strtolower' => 1,
            'spaceCharacter' => '-',
          ),
        ),
      ),
    ),
  ),
),

the config creates following “readable” URL:

http://domain.tld/pageName/urlPath/controller/action/record-title/

but sometimes you used the same term for pageName, urlPath and controller like:

http://domain.tld/job/job/Job/show/my-job-title/

somehow there’s too many “job” in the “readable” URL. how can we spare these repeating paths?
in RealURL there’s a hook to manually influenced the URL en- and decoding. In the RealURL config add following lines

1
2
3
4
5
// realurl Hook for replacing some path
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = array(
  'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
  'decodeSpURL_preProc' => array('user_decodeSpURL_preProc')
);

and add our own userFunc like this

1
2
3
4
5
6
7
function user_encodeSpURL_postProc(&$params, &$ref) {
  $params['URL'] = str_replace('job/job/Job/show/', 'job/', $params['URL']);
}
 
function user_decodeSpURL_preProc(&$params, &$ref) {
  $params['URL'] = str_replace('job/', 'job/job/Job/show/', $params['URL']);
}

the result is a nice short readable URL 🙂

http://domain.tld/job/my-job-title/

One thought on “Extbase and RealURL”

  1. Within the last year realUrl received an update that takes advantage of htmlspecialchars instead of the old lookup tables. I wasn´t able to find out where german umlauts like “ö” are translated into “oe” and why special characters like “&” (ampersand) are not included. So your approach suited we well enough to come up with a fix for the ampersand being translated into “amp” instead of “und” like our customer would have desired.
    This fix is obvious. Though I spent hours googling for “realurl amp und translation” without any sensible result. Hopefully this helps other german realurl users. Thanks for spending the foundation to this, Kartolo 😉

    $GLOBALS[‘TYPO3_CONF_VARS’][‘EXTCONF’][‘realurl’] = array(
    ‘encodeSpURL_postProc’ => array(‘user_encodeSpURL_postProc’),
    ‘decodeSpURL_preProc’ => array(‘user_decodeSpURL_preProc’)
    );

    function user_encodeSpURL_postProc(&$params, &$ref) {
    $params[‘URL’] = str_replace(‘-amp-‘, ‘-und-‘, $params[‘URL’]);
    }

    function user_decodeSpURL_preProc(&$params, &$ref) {
    $params[‘URL’] = str_replace(‘-und-‘, ‘-amp-‘, $params[‘URL’]);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *