Symfony2 - preferred_choices返回错误

时间:2013-01-23 12:45:40

标签: symfony

我想在我的实体形式中使用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。哪里是我的错?

1 个答案:

答案 0 :(得分:0)

尝试在getDefaultOptions()

中用完整实体对象替换(int)1

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