[TYPO3-mvc] extbase/fluid: validating and manipulating data before saving?

Michael Sauter mail at michaelsauter.net
Thu May 13 16:49:00 CEST 2010


> Hey,
>
> i just meant a custom validator like you said -> not automatically.
> But i thought it would be better to build a custom one, then doing it
> withing the setter.
>
> Sascha ;-)

Hey,

thanks for the explanation ... but I think we're talking about different 
things :)
A validator makes sure the value is correct, but doesnt modify the 
value, no?

Let's assume this code:
/**
* Some Date
* @var DateTime
* @validate DateTime
*/
protected $theDate;

/**
  * @param \DateTime $theDate
  */
public setTheDate($theDate) {
  $this->theDate = $theDate;
}

Now, when this setter is called (e.g. when the model is constructed from 
the form), a string is given to setTheDate. This results in a validation 
error (because the property $theDate is not a valid DateTime object). So 
that's why I need to convert the string in the setter to a DateTime 
object. And then you need to add a custom validator for the string 
setter to check that the given string actually can be transformed to a 
DateTime object ...

Or maybe I can't see the forest for the trees ;)

~michael



More information about the TYPO3-project-typo3v4mvc mailing list