简体   繁体   中英

symfony2 - form with date field

I have a problem with a symfony form and a date field. When I view the field, the value retrieved from the database is subtracted a day when it is rendered as a widget single_text and I can not fix it.

For the project I use Symfony 2.6Beta for Bootstrap form support.

The field in form is defined:

$builder->add('natoIl', 'birthday', array(
    'widget' => 'single_text',
    'empty_value' => '',
    'format' => 'dd/MM/yyyy',
    'model_timezone' => 'Europe/Rome',
    'view_timezone' => 'Europe/Rome'
));

I have this problem with MySQL and PostgreSQL.

Thank you very much

EDIT: The problem occurs only with the 'widget' option set to "single_text". I need to see it as text input to add a datepicker field.

EDIT #2:

Doing various tests I found that the problem is when I work with the PHP web server. PHP version I use is 5.5.9-1ubuntu4.5 PC with linux mint.

Possibly you need to set your view and/or model timezone appropriately:

http://symfony.com/doc/current/reference/forms/types/date.html#view-timezone

This is a bug already fixed. The solution is then upgrading symfony.

https://github.com/symfony/symfony/issues/12808

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM