'Typo3 - ReDirect and RouteEnhancer
I am having trouble with my Extbase-Plugin, redirects and route enhancers:
I have a plugin that gets job offers via an API and displays as a list on a Typo3-page. I have written a route enhancer to make the URLs for the single job offers pretty.
If a user clicks on a link, the method "showJob" from the controller is called. This method redirects the user to a different page (I do need two distinct pages for this) and calls the method "showSingleJob".
I have written this redirect like this:
{
$currentPid = $GLOBALS['TSFE']->id;
$jobID = $this->request->getArgument('jobID');
$jobTitle = $this->request->getArgument('jobTitle');
$pageID = $this->request->getArgument('pageID');
$args = [
'jobID' => $jobID,
'jobTitle' => $jobTitle,
"pageID" => $pageID
];
$response = json_decode($this->curl_get_contents('https://api.jobsAPI.com/job/' . $jobID));
if ($pageID != $currentPid) {
$uriBuilder = $this->uriBuilder;
$uri = $uriBuilder
->reset()
->setTargetPageUid(intval($pageID))
->setAddQueryString(TRUE)
->uriFor('showSingleJob', $args, 'UmJobs', 'UmJobs', 'jobliste');
$this->redirectToUri($uri, 0, 404);
}
$this->view->assign('apiJob', $response);
}
The method "showSingleJob" simply gets the data for the desired job and displays it. This works just fine.
But I need pretty urls for the redirected page. At the moment I get my typo3-Url plus all the parameters I am passing. So I tried my hand at a route enhancer:
routeEnhancers:
UmJobs:
type: Extbase
limitToPages:
- 1
- 3
extension: UmJobs
plugin: jobliste
routes:
- routePath: '/karriere/'
_controller: 'UmJobs::list'
- routePath: '/karriere/{jobTitle}/{jobID}/{pageID}'
_controller: 'UmJobs::showJob'
_arguments:
jobTitle: jobTitle
jobID: jobID
pageID: pageID
defaultController: 'UmJobs::showJob'
- routePath: '/karriere/job/{jobTitle}/{jobID}/{pageID}'
_controller: 'UmJobs::showSingleJob'
_arguments:
jobTitle: jobTitle
jobID: jobID
pageID: pageID
defaultController: 'UmJobs::showSingleJob'
requirements:
jobID: '^[0-9].*$'
pageID: '^[0-9].*$'
jobTitle: '^[a-zA-Z0-9].*$'
Again this works fine for "showJobs" but It doens't work at all for "showSingleJobs". It seems as if the enhancer is completely ingored by $uribuilder.
Anyone have an idea what I am doing wrong?
Thanks a lot in advance!
Solution 1:[1]
Seems to me as if your URIs are not unique...
'UmJobs::showJob
routePath: '/karriere/{jobTitle}/{jobID}/{pageID}'
Now lets the values be:
jobTitle = job // Matching the requirement '^[a-zA-Z0-9].*$'
jobID = 123 // Matching the requirement '^[0-9].*$'
pageID = 987 // Matching the requirement '^[0-9].*$'
The path would be: /karriere/job/123/987
'UmJobs::showSingleJob
routePath: '/karriere/job/{jobTitle}/{jobID}/{pageID}'
Now lets the values be:
jobTitle = 123 // Matching the requirement '^[a-zA-Z0-9].*$'
jobID = 987 // Matching the requirement '^[0-9].*$'
pageID = '' // Matching the requirement '^[0-9].*$'
The path would be: /karriere/job/123/987
Conclusion
You can have the same URI for different actions - which can not be served.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Julian Hofmann |
