[Flow] Validation triggered when trying to show object in rest controller

Carsten Bleicker carsten at bleicker.de
Wed Nov 5 13:40:27 CET 2014


but maybe negate it and check for GET/HEAD/... instead.


----------------------

Carsten Bleicker
Wülfingstraße 1
42477 Radevormwald

E-Mail:	carsten at bleicker.de
Web:	www.bleicker.de
Twitter:	@carstenbleicker
Jabber:	cbleicker at jabber.ccc.de
Telefon:	+49 (0)171-2690845

Am 05.11.2014 um 13:39 schrieb Carsten Bleicker <carsten at bleicker.de>:

> Running into the same and solved it by override the action invoking the validation:
> 	/**
> 	 * Invokes only on writing request methods (POST/PUT/PATCH)
> 	 *
> 	 * @return void
> 	 */
> 	protected function initializeActionMethodValidators() {
> 		if ($this->request->getHttpRequest()->getMethod() === 'POST' || $this->request->getHttpRequest()->getMethod() === 'PUT' || $this->request->getHttpRequest()->getMethod() === 'PATCH') {
> 			parent::initializeActionMethodValidators();
> 		}
> 	}
> 
> 
> ----------------------
> 
> Carsten Bleicker
> Wülfingstraße 1
> 42477 Radevormwald
> 
> E-Mail:	carsten at bleicker.de
> Web:	www.bleicker.de
> Twitter:	@carstenbleicker
> Jabber:	cbleicker at jabber.ccc.de
> Telefon:	+49 (0)171-2690845
> 
> Am 05.11.2014 um 13:21 schrieb Christian Loock <chl at vkf-renzel.de>:
> 
>> Hello,
>> 
>> I am currently trying to implement a simple REST Controller. I defined a route like so:
>> 
>> -
>> name:'Project REST by FileSystem Name'
>> uriPattern:'REST/project/{project.fileSystemName}'
>> defaults:
>>   '@format':'json'
>>   '@package':'RA.ReleaseManager'
>>   '@controller':'projectRest'
>> routeParts:
>>   project:
>>     objectType:'RA\ReleaseManager\Domain\Model\Project'
>> 
>> If I now try to call the controller, the validation of the Project Model is triggered:
>> 
>> Validation failed while trying to call RA\ReleaseManager\Controller\ProjectRestController->showAction().
>> 
>> In the Model, I have defined Validation for a property:
>> 
>> /**
>> * The name, working copies of this project get in the file system, eg. flow_vkf_admin
>> *@varstring
>> *@Flow\Validate(type="RegularExpression", options={"regularExpression"="/^[^_]*_[^_]*_[^_]*$/"})
>> *@Flow\Validate(type="NotEmpty")
>> */
>> protected$fileSystemName;
>> 
>> But I wonder, why this is even triggered, and why it throws an error, since it is a model, that has been created before using the MVC stack, running through validation just fine. Unfortunatly it doesnt give me any further information on why the validation fails. I already looked into the logs, with no success in finding what is going wrong here.
>> 
>> So this let's me with a couple of questions:
>> 
>> 1. Why is Validation even triggered on a safe (GET) request.
>> 2. How is it possible that the validation fails, for an object that should be loaded from the database, according to the routing.
>> 3. Where can I see why the validation fails in a REST controller?
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
> 



More information about the Flow mailing list