尝试在Symfony2中使用嵌入表单时出错

Fae*_*ery 6 forms symfony

我正在尝试嵌入一个表单集合,如下所示 - http://symfony.com/doc/current/cookbook/form/form_collections.html

我几乎从那里重写代码,但我遇到了两个问题:

  1. 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

  2. form_start()函数不存在.

您有什么想法如何解决第一个问题?什么都没有帮助:(

PS我没有添加任何代码,因为它与书中的相同,我只更改了名称(或者至少我认为是这样),如果需要,我会添加任何代码.

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';
    }
} 
Run Code Online (Sandbox Code Playgroud)

Stu*_*haw 18

你错过了

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
Run Code Online (Sandbox Code Playgroud)

来自你的进口.