已检查 Doctrine 2 ObjectMultiCheckbox 属性

Doctrine 2 ObjectMultiCheckbox checked property

我被关注了: ZF2,学说 2,多对多。

问题:如何使复选框在视图中实际选中?似乎可以通过使用名称约定来完成。 有人可以给我建议吗?

关系是:

Portfolio.php
/**
 * @var \Doctrine\Common\Collections\Collection
 * @ORM\ManyToMany(targetEntity="Worker", inversedBy="portfolio")
 * @ORM\JoinTable(name="portfolio_workers",
 * joinColumns={@ORM\JoinColumn(name="portfolio_id",referencedColumnName="id")},
 * inverseJoinColumns={@ORM\JoinColumn(name="worker_id",referencedColumnName="id")}

 * )
 */
private $workers;

Worker.php
/**
 * @ORM\ManyToMany(targetEntity="Portfolio", mappedBy="workers")
 */
private $portfolio;

还有元素添加代码是:

$this->add(array(
        'name' => 'workerId',
        'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
        'options' => array(
            'label' => 'TESTE',
            'object_manager' => $this->getObjectManager(),
            'target_class'   => 'Backend\Entity\Worker',
            'property'       => 'name'
        )
    ));

感谢大家,看来我找到了解决方案。我刚刚更改了以下表单元素代码:

$this->add(array(
    'name' => 'workers',
    'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
    'options' => array(
        'label' => 'TESTE',
        'object_manager' => $this->getObjectManager(),
        'target_class'   => 'Backend\Entity\Worker',
        'property'       => 'name'
    )
));

也许对像我这样困倦的人有帮助)