Symfony2:默认表单类型猜测器损坏
Symfony2: Default Form Type Guesser broken
我以某种方式设法破解了 symfony 2.6 的默认表单类型猜测器。让我向您展示一些简单的代码:
ExampleType.php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ExampleType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('test') // should be a text type because it's stored as string
;
}
...
}
但是当我调用表单时,我得到了一个未捕获的 PHP 异常:
Symfony\Component\Form\Exception\InvalidArgumentException: "Could not load type "Symfony\Component\Form\Extension\Core\Type\TextType"" at /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php line 83
堆栈跟踪:
[1] Symfony\Component\Form\Exception\InvalidArgumentException: Could not load type "Symfony\Component\Form\Extension\Core\Type\TextType"
at n/a
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php line 83
at Symfony\Component\Form\FormRegistry->getType('Symfony\Component\Form\Extension\Core\Type\TextType')
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 82
at Symfony\Component\Form\FormFactory->createNamedBuilder('test', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array('required' => false))
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 132
at Symfony\Component\Form\FormFactory->createBuilderForProperty('AppBundle\Entity\Example', 'test', null, array())
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 109
at Symfony\Component\Form\FormBuilder->create('test', null, array())
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 267
at Symfony\Component\Form\FormBuilder->resolveChildren()
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 215
at Symfony\Component\Form\FormBuilder->getForm()
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 39
通过显式传递表单类型作为第二个参数(在本例中 'text')来规避此异常是没有问题的,但我想知道什么可以阻止默认表单类型猜测器正常工作。
有什么建议吗?
格雷格
好吧,毕竟我不知道我是怎么搞混的,但是 clearing composer cache 在重新安装 symfony 2.6 之前确实修复了它。
我以某种方式设法破解了 symfony 2.6 的默认表单类型猜测器。让我向您展示一些简单的代码:
ExampleType.php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ExampleType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('test') // should be a text type because it's stored as string
;
}
...
}
但是当我调用表单时,我得到了一个未捕获的 PHP 异常:
Symfony\Component\Form\Exception\InvalidArgumentException: "Could not load type "Symfony\Component\Form\Extension\Core\Type\TextType"" at /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php line 83
堆栈跟踪:
[1] Symfony\Component\Form\Exception\InvalidArgumentException: Could not load type "Symfony\Component\Form\Extension\Core\Type\TextType"
at n/a
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php line 83
at Symfony\Component\Form\FormRegistry->getType('Symfony\Component\Form\Extension\Core\Type\TextType')
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 82
at Symfony\Component\Form\FormFactory->createNamedBuilder('test', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array('required' => false))
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 132
at Symfony\Component\Form\FormFactory->createBuilderForProperty('AppBundle\Entity\Example', 'test', null, array())
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 109
at Symfony\Component\Form\FormBuilder->create('test', null, array())
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 267
at Symfony\Component\Form\FormBuilder->resolveChildren()
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 215
at Symfony\Component\Form\FormBuilder->getForm()
in /home/gv/PhpstormProjects/vcb/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 39
通过显式传递表单类型作为第二个参数(在本例中 'text')来规避此异常是没有问题的,但我想知道什么可以阻止默认表单类型猜测器正常工作。
有什么建议吗?
格雷格
好吧,毕竟我不知道我是怎么搞混的,但是 clearing composer cache 在重新安装 symfony 2.6 之前确实修复了它。