[TYPO3-mvc] Re: Redirect instead of forward on action error

Viktor Livakivskyi invisible.kinder at gmail.com
Mon Oct 5 15:35:15 CEST 2015


Okay, after some tries and errors there is a "hacky" way to do this.

First we need to override forwardToReferringRequest() and add $this->request and $this->arguments->getValidationResults() into session by $GLOBALS['TSFE']->fe_user->setKey(...). And, sure, exchange forward() with redirect() with adding desired page-uid as 5th parameter for redirect-method.

Next the data needs to be restored in initializeAction():
$originalRequest = $GLOBALS['TSFE']->fe_user->getKey('ses', 'originalRequest');
$validationResults = $GLOBALS['TSFE']->fe_user->getKey('ses', 'validationResults');

if($originalRequest !== NULL) {
	$this->request->setOriginalRequest($originalRequest);
	$this->request->setOriginalRequestMappingResults($validationResults);
}

$GLOBALS['TSFE']->fe_user->setKey('ses', 'originalRequest', NULL);
$GLOBALS['TSFE']->fe_user->setKey('ses', 'validationResults', NULL);


And this works. But... not all cases are covered. In fact, when you have more, than 2 steps and you're creating an object, then this will break, when you'll try to redirect from 3rd step to 2nd, because object is not yet created and it has no 'uid'. So, when trying to build an URI for 2nd step Extbase dies, because only 'uid' can be used as object identifier.

For me it looks like missing feature, so I've made a feature request on Forge: https://forge.typo3.org/issues/70384


More information about the TYPO3-project-typo3v4mvc mailing list