我刚刚将symfony从2.7更新到3.0并且遇到了一些问题..
它无法加载我的表单类型.这是一个例子.
的services.xml
app.search: class: AppBundle\Form\Type\SearchFormType tags: - { name: form.type,alias: app_search }
多数民众赞成我试图创造形式.
$form = $this->createForm('app_search',new Search());
SearchFormType
namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class SearchFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder,array $options) { $builder->add('phrase','text'); } public function getBlockPrefix() { return 'app_search'; } }
得到下一个错误:
An exception has been thrown during the rendering of a template
(“Could not load type “app_search””) in ….
在symfony 3.0中应该如何?
谢谢 !
您应该将设置更改为..
app.search: class: AppBundle\Form\Type\SearchFormType tags: - { name: form.type }
并在您的表单类型
use Symfony\Component\Form\Extension\Core\Type\TextType; // ... $builder->add('phrase',TextType::class);
然后叫它用…
$form = $this->createForm(SearchFormType::class,new Search()); // or $form = $this->createForm('AppBundle\Form\Type\SearchFormType',new Search());
它的长短是表单不再被命名,它们由类名引用.