[TYPO3-dev] extbase/fluid: validating and manipulating data before saving?
Michael Sauter
mail at michaelsauter.net
Wed May 12 11:04:43 CEST 2010
On 12.05.10 09:50, Sven Kalbhenn wrote:
> Hi guys!
>
> I'm writing a new extension for "plane-reservations" with extbase and fluid.
> For the reservation, I need a frontend-form with a date- and time-field.
> If I understand everything right, I have to write a new ViewHelper for rendering the form.
> OK, but where is the correct place for the validation and transforming the posted values into a DateTime-Object?
>
> If I send the date as a string, I always get the error:
> "Tx_Planereservation_Domain_Model_Reservation::setStart() must be an instance of DateTime, string given in .../typo3conf/ext/planereservation/Classes/Domain/Model/Reservation.php"
>
> I think the setter-method of the model is the wrong place - because the persistent-manager will use this method as well.
> So, is the controller the correct place??? Or is there a mechanism - like the ViewHelpers - to validate and manipulate the data before saving it?
>
> Can someone explain it to me? Or is there a documentation for such problems?
>
> CU...Sven Kalbhenn
Hey,
First off: I think the typo3v4mvc mailinglist would be better to ask
this question, as there are more extbase developers there (I guess).
Anyway, here's what I would do:
Add an additional setter/getter to your model, which deals with the
string version of the DateTime. Use this "string version" getter in the
fluid form.
The setter sets the DateTime object property of the model. The getter
just uses DateTime::format to get the string representation of the date.
That works for me (well, this works in FLOW3, haven't tested with
Extbase) and is IMHO the easiest solution (although you then have to
deal with validation on your own).
~michael
More information about the TYPO3-dev
mailing list