0

我想preferred_choices在我的实体表单中使用:

public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder->add('id','entity', array(
        'class'=>'GameShelf\UsersBundle\Entity\OwnState',
        'property' => 'name',
        'attr' => array('class'=>'chzn-select selectBig', 'data-placeholder'=>'Mam...'),
        'label' => ' ',
        'empty_value' => '',
        'preferred_choices' => array($options['selected'])
    ));
}

public function getDefaultOptions(array $options) {
    return array(
        'data_class' => 'GameShelf\UsersBundle\Entity\OwnState',
        'selected' => 1
    );
}

但它返回一个错误:Warning: spl_object_hash() expects parameter 1 to be object, integer given. 我的错在哪里?

4

1 回答 1

0

尝试用 getDefaultOptions() 中的完整实体对象替换 (int)1

https://github.com/symfony/symfony/pull/5277

于 2013-01-23T13:04:49.437 回答