カスタムの DateType クラスを作成したいと思います。これを行うために、クラスSymfony\Component\Form\Extension\Core\Type\DateTypeを src/ ディレクトリにコピーし、クラス名とgetName()
.
<?php
namespace FooBar\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
// ...
class MonthType extends AbstractType
{
// ...
public function getName()
{
return 'month';
}
// ...
}
新しいタイプも登録しました:
foobar.form.type.month:
class: FooBar\CoreBundle\Form\Type\MonthType
tags:
- { name: form.type, alias: month }
ただし、新しい型を使用しようとすると、例外 ( Array to string conversion in /var/www/foobar/app/cache/dev/twig/4d/99/945***.php
) がスローされます。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$default = new \DateTime('now');
$builder
->add('season', 'month', array('data' => $default))
;
}
注:すべてに変更'month'
すると、'date'
問題なく動作します。
例外がスローされる理由と、それを取り除く方法を知っている人はいますか?