[Flow] Validation > Exception instead of going back to newAction
Stephan Schuler
Stephan.Schuler at netlogix.de
Fri Dec 6 11:41:13 CET 2013
Hi Axel.
Do I get you right: The whole strange validation issue could be avoided if Doctrine would deal with your Oracle database properly? Then ... fixing Doctrine could be way easier :).
If so, then you could try to use overrule the \Doctrine\DBAL\Types\DateTimeType object as a local Doctrine hotfix.
The \Doctrine\DBAL\Types objects are Doctrines internal type converters that make e.g. strings out of DateTime objects when mapping PHP to DB and DateTime out of strings when mapping the other way around.
You need to register them as an alternative:
\Doctrine\DBAL\Types\Type::overrideType('datetime', 'YourVendor\\YourPackage\\Doctrine\\DBAL\\Types\\AlternateDateTimeType');
Then you create the AlternateDateTimeType extending Doctrines original DateTimeType.
And now you can do whatever needs to be done do pass DateTime objects properly to your Oracle DB.
Hint:
I used an aspect pointing at '@Flow\After("method(TYPO3\Flow\Persistence\Doctrine\PersistenceManager->initialize())")' to call the overrideType method.
Here is the documentation part where I learned how Doctrines DBAL Types work. It's not really related to how DBMS deal with input types but refers to UTC date time conversion is this document, but I guess that shouldn't hinder you from using it.
http://docs.doctrine-project.org/en/2.0.x/cookbook/working-with-datetime.html#handling-different-timezones-with-the-datetime-type
To sum it up:
* I would definitively use the default DateTime object wherever I can. Especially in setters and getters of the domain object.
* Validation should be no problem here.
* If "no time given" is a valid option, just don't add the "NotEmpty" validator.
* If it's kind of creation or manipulation time, I would use the __construct of the object itself to start with new a new DateTime object. This even avoids the "NotEmpty" requirement.
* If it's really a DBMS deal, try to fix Doctrine instead of adjusting your model to it.
Kind regards,
Stephan Schuler
Web-Entwickler
Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de
--
netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de
netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt
-----Ursprüngliche Nachricht-----
Von: flow-bounces at lists.typo3.org [mailto:flow-bounces at lists.typo3.org] Im Auftrag von Axel Wüstemann
Gesendet: Freitag, 6. Dezember 2013 11:15
An: TYPO3 Flow mailing list
Betreff: Re: [Flow] Validation > Exception instead of going back to newAction
Am 06.12.2013 11:03, schrieb Stephen Bungert:
>> My object hast a property date. In the form I need to split the date
>> into __date and __time.
>
> Maybe you can use javascript to combine the values from your date and
> time fields into one datetime value that your model needs? Then it
> would have the property and it could be validated.o
I even could avoid using Flow... ;=)
In principle it is a good idea, but doesn't conform to the idea of DDD where validation rules are business rules. That's why they should be placed in the domain models.
This was one reason for me to choose Flow. This project Im working on ports an old Zend Framework application from 2009, now to Flow.
>
>> The MVC base validate will not act, because ther is nor date property
>> to validate. So it comes to the persistence valitation wich throws an
>> exeption.
>
> Have you tried validating the whole object instead of just the
> properties? This is an annotation on the controller action not the
> model. maybe you could then use your buildDateTime method to make sure
> your model validates.
How to do this? I added my validation rules to the properties to be validated and in case of the date property I run into this issue. What other I could do?
_______________________________________________
Flow mailing list
Flow at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list