Error trying to use inline forms in Symfony2

I am trying to implement a collection of forms as shown here - http://symfony.com/doc/current/cookbook/form/form_formlections.html

I almost rewrote 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

  • The form_start () function does not exist.

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

PS I am not adding any code, because it is the same as in the book, I just changed the names (or at least I think so), I will add the code if necessary.

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'; } } 
+6
source share
1 answer

You are lacking

 use Symfony\Component\OptionsResolver\OptionsResolverInterface; 

from your import.

+18
source

Source: https://habr.com/ru/post/950816/


All Articles