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

"Christian Müller (FLOW3 Team)" christian.mueller at typo3.org
Fri May 4 09:59:01 CEST 2012


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.
>
>


-- 
Christian Mueller
TYPO3 Core Team

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the FLOW3-general mailing list