Doctrine Module objectSelect setvalue 不起作用

Doctrine Module objectSelect setvalue not working

我有一个关于 Doctrine 模块对象的简单问题 Select。

我有一个简单的对象Select表单元素

       $this->add(array(
            'name' => 'timezone',
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
            'options' => array(
                'label' => _('Timezone:'),
                'label_attributes' => array('class' => 'required'),
                'object_manager' => $this->getEntityManager(),
                'target_class' => 'Application\Entity\Timezones',
                'property' => 'timezone',
                'is_method' => true,
                'find_method' => array(
                    'name' => 'FindAll',
                ),
            ),
        ));

现在我想select某个选项作为默认值,我已经使用setValue方法来做到这一点,但它不起作用。

$this->get('timezone')->setValue(335);

有人知道这是为什么吗?

非常感谢。

我明白了为什么它不起作用。

在我的控制器中,我将我的表单绑定到一个空的 Doctrine 实体。这超越了我设定的价值观。我在绑定表单后在我的控制器中添加了值,这解决了问题。

$entityManager = $this->getEntityManager();
$site = new Sites($this->getServiceLocator());
$form = new AddSiteForm($this->getServiceLocator());
$form->setHydrator(new DoctrineObject($entityManager));
$form->bind($site);
$form->get('timezone')->setValue(335);
$form->get('currencyCode')->setValue('GBP');