6

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:

  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() function doesn't exist.

Do you have any ideas how to solve the first problem? Nothing helps :(

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';
    }
} 
1
  • You're going to have to at least show us ExpenseType.php Commented Aug 1, 2013 at 13:13

1 Answer 1

18

You're missing

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

from your imports.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.