New in Symfony 4.1: Added support for immutable dates in forms
The DateTimeImmutable class was introduced in PHP 5.5. It provides the same
DateTime, but when calling to its
it returns a new
DateTimeImmutable object to not change the original value.
In recent Symfony versions we added support for immutable dates in several parts of the framework. In Symfony 4.1 we finished a long-standing petition from the community to add support for immutable dates in Symfony Forms.
1 2 3 4 5
use Symfony\Component\Form\Extension\Core\Type\DateTimeType; $builder->add('startsAt', DateTimeType::class, array( 'input' => 'datetime_immutable', ));
Now you can set a
DateTimeImmutable object as the value of this field and
when the form is submitted and valid, you'll get a
back with the new value set by the user.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.