[FLOW3-general] How can i catch TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException in controllerAction

mosaiq_marcel mosaiq_marcel at web.de
Fri May 4 10:58:24 CEST 2012


Hi Christian,

in my case, i don't have an object which comes into my action (see my 
first post). Instead, I create all the needed objects within the 
controller action. So what do you think is the preferred way?

Although currently I can catch the exception but still get shown the 
FLOW3 error message until my redirect is executed:

public function createAction() {
     ...
     try {
         $this->partyRepository->add($person);
         $this->persistenceManager->persistAll();
     }catch 
(\TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException $e) {
         $this->flashMessageContainer->addMessage(new Message('...'));
         $this->redirect('register');
	}
     ...
}

So how can i hide the FLOW3 error message? I am grateful for any help.

Best regards,
Marcel

Am 04.05.2012 09:59, schrieb "Christian Müller (FLOW3 Team)":
> Hi,
>
> just a small note to both of you. The described way shouldn't be needed
> and used. Actually validations are executed twice, first when you expect
> an object in your action it will be validated when your action is called
> and you come back to the previous action in case the validation failed.
> That is the point you can and should take action.
>
> The second time validation is triggered on persist to prevent
> unvalidated content in the database, but at this point it is merely a
> last check, it shouldn't happen that you have unvalidated objects.
>
> Cheers,
> Christian
>
> On 03/05/12 21:58, Pankaj Lele wrote:
>> Hi Marcel,
>>
>>> How can i catch this exception to give back a user friendly error
>>> message?
>>
>> You have to explicitly call the persistenceManager->persistAll() after
>> the repository operation to catch exception. ->persistAll() is by
>> default called after the action is executed somewhere in the core.
>>
>> So you can just inject the persistenceManager in your controller
>>
>> /**
>> * @var \TYPO3\FLOW3\Persistence\PersistenceManagerInterface
>> * @FLOW3\Inject
>> */
>> protected $persistenceManager;
>>
>> and then right after the $this->partyRepository->add($person); you can
>> add a line $this->persistenceManager->persistAll(); and you will be able
>> to catch the exception.
>>
>>
>
>


More information about the FLOW3-general mailing list