Zend Framework 2 Doctrine 2 one-to-many checkbox hydration

class RoleForm extends Form implements InputFilterProviderInterface
{
    public function __construct(ObjectManager $objectManager)
    {
        // ...

        $this->add(array(
            'name' => 'rolePermissions',
            'type' => 'Zend\Form\Element\Collection',
            'options' => array(
                'label' => 'Role Permissions',
                'count' => 0,
                'should_create_template' => true,
                'allow_add' => true,
                'target_element' => array(
                    'type' => 'Zend\Form\Fieldset',
                    'options' => array(
                        'use_as_base_fieldset' => true
                    ),
                    'elements' => array(
                        // add form fields for the properties of the RolesPermissionsEntity class here
                        array(
                            'name' => 'id',
                            'type' => 'Zend\Form\Element\Hidden',
                        ),
                        array(
                            'name' => 'role',
                            'type' => 'Zend\Form\Element\Checkbox',
                            // other options
                        ),
                        // ...
                    ),
                ),
            ),
        ));

        // ...
    }

    // ...
}

Leave a Comment

tech