..." /> ..." /> ..."/>

ZF2 / Doctrine Form Multi-select Element for Many-to-Many Relation

878 views Asked by At

If I have 2 entities related as "many-to-many", it's quite easy to draw a multi-select element in the form (for example Product <- many-to-many -> Category):

ProductFieldset:

    $this->add(array(
        'type' => 'DoctrineModule\Form\Element\ObjectSelect',
        'name' => 'category',
        'attributes' => array(
            'multiple' => 'multiple',
        ),
        'options' => array(
            'target_class' => 'Application\Entity\Category',
            'property' => 'name',
            'label' => 'Select categories',
            'find_method' => array(
                'name' => 'findAll',
            ),
        ),
    ));

But how can I implement the multi-select box if these entities are linked with help of third object? (Product <- many-to-one -> ProductCategory <- one-to-many -> Category).

Usually I use Form Collections for that (http://framework.zend.com/manual/current/en/modules/zend.form.collections.html) but sometimes it'd be more convenient to use simple multi-select element wrapped by some jQuery plugin.

0

There are 0 answers