ruwork/polyfill-form-dti-bundle
最新稳定版本:0.2.1
Composer 安装命令:
composer require ruwork/polyfill-form-dti-bundle
包简介
Symfony Form polyfill bundle adding input=datetime_immutable to date types.
README 文档
README
This package is a polyfill bundle for my pull request adding input=datetime_immutable option to the Symfony date and time form types.
Works with PHP >=5.5 and Symfony >=2.8.
Internally this bundle uses the ruwork/polyfill-form-dti package and plugs its type extensions and guesser into DI with all necessary tags.
Installation
composer require ruwork/polyfill-form-dti-bundle
Enable the Ruwork\PolyfillFormDTIBundle\RuworkPolyfillFormDTIBundle manually in your kernel if you don't use Symfony Flex.
Usage
<?php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; /** * @Entity */ class Survey { /** * @ORM\Column(type="date_immutable") * * @var \DateTimeImmutable */ private $dayOfBirth; public function getDayOfBirth() { return $this->dayOfBirth; } public function setDayOfBirth(\DateTimeImmutable $dayOfBirth) { $this->dayOfBirth = $dayOfBirth; } }
<?php namespace App\Controller; use App\Entity\Survey; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\HttpFoundation\Request; class FormController extends AbstractController { /** * @Route("/form") * @Template */ public function __invoke(Request $request) { $survey = new Survey(); $form = $this->createFormBuilder($survey) ->add('dayOfBirth', DateType::class, [ 'input' => 'datetime_immutable', ]) // or let the form guesser do the job for you ->add('dayOfBirth') ->getForm() ->handleRequest($request); return [ 'form' => $form->createView(), ]; } }
Bundle will automatically register the Ruwork\PolyfillFormDTI\Guesser\DoctrineOrmDTIGuesser if Doctrine DBAL's version is >=2.6 and @doctrine service is registered in DI.
Testing
vendor/bin/simple-phpunit
统计信息
- 总下载量: 52.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-11