0

在我的typo3流应用程序中,我想在将异常作为闪存消息抛出后停止执行。因此我写了这个:

public function updateAction(Mitglied $mitglied) {

   if ($xy == 'z') {
       try {
           throw new \TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException('Fehler: In dieser Kombination nicht zulässig', 1);
       } catch (\TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException $e) {
           $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error($e->getMessage()));
       }
   }

   $this->mitgliedRepository->update($mitglied);
   $this->addFlashMessage('Mitglied erfolgreich geändert.');
   $this->redirect('index');
}

如我所愿,该消息显示为闪存消息。但是函数的执行并没有停止。有谁知道,为什么以及如何预防?如果条件为真,则需要重定向到原始操作。

4

1 回答 1

0

我现在用以下代码得到它:

// get back to originating request - see https://git.typo3.org/Packages/TYPO3.Flow.git/blob/master:/Classes/TYPO3/Flow/Mvc/Controller/ActionController.php

$referringRequest = $this->request->getReferringRequest();
if ($referringRequest === NULL) {
      return;
}
$packageKey = $referringRequest->getControllerPackageKey();
$subpackageKey = $referringRequest->getControllerSubpackageKey();
if ($subpackageKey !== NULL) {
        $packageKey .= '\\' . $subpackageKey;
}
$argumentsForNextController = $referringRequest->getArguments();
$argumentsForNextController['__submittedArguments'] = $this->request->getArguments();
$argumentsForNextController['__submittedArgumentValidationResults'] = $this->arguments->getValidationResults();
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $packageKey, $argumentsForNextController);

最后,这要容易得多:

$this->errorAction()->forwardToReferringRequest();
于 2015-06-10T12:01:23.867 回答