jeudi 28 janvier 2016

Symfony2: FormType Collections as Checkboxes

I have a model CostTypeConnection which has an one to many relation to DepartmentConnection.

I want, that the DepartmentConnection is displayed as checkboxes.

My CostTypeConnection Class has a variable $costType, which is an Entity CostType, that has a $name varaible in it.

My DepartmentConnection Class has a variable $department, which is an Entity Department, that has also a $name variable.

My CostTypeFormType:

  ....    
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('costType', 'text', array(
                'label' => 'costType'
            ))
            ->add('departmentConnections', 'collection', array(
                'type' => new DepartmentConnectionType(),
                'allow_add'    => false,
                'label' => false,
                'by_reference' => false,
                'options' => array('label' => false),

            ))
        ;
    } ...

My DepartmentConnection:

...
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('department', 'text', array(
                'label' => false
            ))
        ;
    }...

So it is not possible to define a checkbox-Type in my Formbuilder for department, because it is an entity and not a variable. Has someone an idea what I can do? This doesnt work in my DepartmentConnectionType Class:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('department', 'choice', array(
                'label' => false
            ))
        ;
    }

It finishs with the error:

The value of type "object" cannot be converted to a valid array key

THANKS FOR ANY HELP!!!




Aucun commentaire:

Enregistrer un commentaire