尝试在Symfony2中使用嵌入式表单时出错 [英] Error when trying to use embedded forms in Symfony2
问题描述
我正在尝试嵌入如下所示的表单集合- http://symfony. com/doc/current/cookbook/form/form_collections.html
I'm trying to Embed a Collection of Forms just as shown here - http://symfony.com/doc/current/cookbook/form/form_collections.html
我几乎从那里重写了代码,但是遇到了两个问题:
I almost rewrite the code from there but I met two problems:
-
FatalErrorException: Compile Error: Declaration of MyBundle\Form\Type\ExpenseType::setDefaultOptions() must be compatible with that of Symfony\Component\Form\FormTypeInterface::setDefaultOptions() in MyBundle\Form\Type\ExpenseType.php line 33
form_start()函数不存在.
form_start() function doesn't exist.
您对如何解决第一个问题有任何想法吗?没有任何帮助:(
Do you have any ideas how to solve the first problem? Nothing helps :(
P.S.我没有添加任何代码,因为它与书中的代码相同,只是更改了名称(或者至少我认为是这样),如有需要,我将添加任何代码.
P.S. I'm not adding any code, because it's the same as in the book, I only changed the names (or at least I think so), I'll add any code if needed.
ExpenseType.php
<?php
namespace MyBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class ExpenseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', 'text',array(
'label' => ' '));
$builder->add('description', 'textarea',array(
'label' => ' '));
$builder->add('expenseVariants', 'collection', array('type' => new ExpenseVairantType()));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'MyBundle\Entity\Expense',
));
}
public function getName()
{
return 'expense';
}
}
推荐答案
您丢失了
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
从您的进口.
这篇关于尝试在Symfony2中使用嵌入式表单时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!