PHP code example of ruwork / polyfill-form-dti

1. Go to this page and download the library: Download ruwork/polyfill-form-dti library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ruwork / polyfill-form-dti example snippets




use Ruwork\PolyfillFormDTI\DTIExtension;
use Ruwork\PolyfillFormDTI\Guesser\DoctrineOrmDTIGuesser;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\Forms;

/** @var \Doctrine\Common\Persistence\ManagerRegistry $registry */

$factory = Forms::createFormFactoryBuilder()
    ->addExtension(new DTIExtension())
    // Optionally you can add a Doctrine ORM guesser
    // to guess input=datetime_immutable for Doctrine 2.6 immutable date types. 
    ->addTypeGuesser(new DoctrineOrmDTIGuesser($registry))
    ->getFormFactory();

$form = $factory
    ->createBuilder(FormType::class, [
        'datetime' => new \DateTimeImmutable('1828-09-09 12:00:00'),
        'date' => new \DateTimeImmutable('1860-01-29'),
        'time' => new \DateTimeImmutable('23:59'),
    ])
    ->add('datetime', DateTimeType::class, [
        'input' => 'datetime_immutable',
    ])
    ->add('date', DateType::class, [
        'input' => 'datetime_immutable',
    ])
    ->add('time', TimeType::class, [
        'input' => 'datetime_immutable',
    ])
    ->getForm();