Thursday, October 22, 2015

cakephp 3.1 - mySQL data field types of DATE and TIME don't seem to populate the input fields correctly when using input type = text

Since I don't want to use 3 fields of input for a date, the idea of using a text field with a datepicker seemed logical.

I've set :   
    //Config\USER_LOCALE = 'en_US'

    I18n
::locale( Config\USER_LOCALE );
   
Time::$defaultLocale =  Config\USER_LOCALE;

So I'm expecting the have a date formatted as 9/5/2015.

At the time $this->Form->input is called with type=text, the Entity holds:
+ [on_date]
    $_fomatters
    $_toStringFormat
[ 3, 3 ]
    $date
= 2015-09-05 00:00:00.000000
    $defaultLocale
= en_US
    $timezone
= UTC
    $toStringFormat
= Y-m-d H:i:s


The toStringFormat is what mySQL wants to give use for a DATETIME, and what it wants back of course.  I was expecting to get the Y-m-d format for the input field... but the input field is created and populated with "9/5/15, 12:00 AM"  Which is correct form for LOCALE, but has time involved.

Since this is a DATE field, the time specifier should not be there... the opposite is true when I have a TIME field... it has a DATE.

It would seem to me that the Time routine that is called as the text field is populated should at least use the LOCALE format for the DATE and leave the time out!  Then maybe the Validation routines would work.  If it uses the toStringFormat of the date object, that would be ok with me as long as the time is left out.

Now, I can get what I want... but I have to drop the ORM and get a ->hydrate(false)->toArray() ...alter the date and time field to use the locale and no time...  edit... build an entity from array, change the format of the date and time to keep mySQL happy, and then save.

As usual, there is probably something very simple that I've missed, but I've wasted a lot of time trying to get this to work the "cakePHP" way.  Any ideas, or suggestions would be greatly appreciated.








--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: