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() 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';
}
}
You're missing
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
from your imports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With