Doctrine orm 条令模块对象选择设置值不工作
我有一个关于对象选择的简单问题 我有一个简单的objectSelect表单元素Doctrine orm 条令模块对象选择设置值不工作,doctrine-orm,zend-framework2,Doctrine Orm,Zend Framework2,我有一个关于对象选择的简单问题 我有一个简单的objectSelect表单元素 $this->add(array( 'name' => 'timezone', 'type' => 'DoctrineModule\Form\Element\ObjectSelect', 'options' => array( 'label' => _('Timezone
$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',
),
),
));
现在我想选择一个特定的选项作为默认值,我已经使用了setValue方法来实现这一点,但它不起作用
$this->get('timezone')->setValue(335);
有人知道这是为什么吗
非常感谢。我弄明白了为什么它不起作用
$this->get('timezone')->setValue(335);
在我的控制器中,我将我的表单绑定到一个空的条令实体。这覆盖了我设置的值。绑定表单后,我在控制器中添加了值,这解决了问题
$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');
是否有id为335的时区?是的,在生成的HTML的选项列表中。