[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 11:20:44 CEST 2012


You could accept the needed arguments as strings (email, name, pass) and 
add validation annotations to your action, then you have the same result 
as using an object.

Cheers,
Christian

On 04/05/12 10:58, mosaiq_marcel wrote:
> 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.
>>>
>>>
>>
>>


-- 
Kitsunet
Christian Müller

http://www.kitsunet.de

Mail: christian at kitsunet.de
Fon: +49 (0)228-85029939
Mobil: +49 (0)172-1091412

Dankwardstraße 6, 53179 Bonn, Germany



More information about the FLOW3-general mailing list