简体   繁体   中英

TYPO3 RealUrl - shorten extbase detail path to second level

I have an own Plugin for Jobs with a list and a show View (on the same page). I entered my params in the "postVarSets" in the realurl_conf.php (grouped by "job-view") and so my Links look like following:

/jobs - List View

/jobs/job-view/show/Job/testjob - Detail View


Now i can shorten my path with the "encodeSpURL_postProc":

$params['URL'] = str_replace('job-view/show/Job', 'job-detail', $params['URL']);

and decode by

$params['URL'] = str_replace('job-detail', 'job-view/show/Job', $params['URL']);

/jobs - List View

/jobs/job-detail/testjob - Detail View


But i want my Detail View to look like:

/jobs/testjob

But I can't use

$params['URL'] = str_replace('jobs/job-view/show/Job', 'jobs', $params['URL']);

because the decode

$params['URL'] = str_replace('jobs', 'jobs/job-view/show/Job', $params['URL']);

would also try to decode the List View back.


So, is it possible to shorten the URL path of the detail page to the second level?

This is very easy to achieve using a combination of fixedPostVars and TS conditions.

Assuming that your extensions's parameters are something like tx_jobs_list , you will have the following in the realurl config:

'fixedPostVars' => [
   $jobDetailPagePid => [
        [
            'GETvar' => 'tx_jobs_list[uid]',
            'lookUpTable' => [
                ...
            ]
        ],
        [
            'GETvar' => 'tx_jobs_list[controller]',
            'noMatch' => 'bypass'
        ],
        [
            'GETvar' => 'tx_jobs_list[action]',
            'noMatch' => 'bypass'
        ],
   ],
],

$jobDetailPagePid must be a page id. You cannot use _DEFAULT here.

You also need TS conditions for the detail page:

[globalString = GP:tx_jobs_list|uid = /\d+\]
config.defaultGetVars {
    tx_jobs_list {
        controller = List
        action = single
    }
}
[global]

That's all.

Take a closer look at the documentation: https://github.com/dmitryd/typo3-realurl/wiki/Configuration-reference#fixedpostvars Maybe this can help you.

I never had to change the decode/encode functions to get what I need.

You can use encodeSpURL_postProc and decodeSpURL_preProc in your real_conf.php file like below.

'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
'decodeSpURL_preProc' => array('user_decodeSpURL_preProc'),

function user_encodeSpURL_postProc(&$params, &$ref) {
   $params['URL'] = str_replace('jobs', 'job-view/show/Job/', $params['URL']);
}
function user_decodeSpURL_preProc(&$params, &$ref) {
   $params['URL'] = str_replace('job-view/show/Job/', 'jobs', $params['URL']);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM