douer9399 2014-11-22 14:47
浏览 50

preferred_choices实体字段表单永远不会运行

I want to set a form with a "preferred_choices" on top of my select field HTML corresponding to previous submitted datas selected by the user. I want to construct an entity field with a constant list AND a preferred_choices top element if the form is previously submitted.

I never ran correctly this function in symfony2. Can you help me to construct correctly my field form.

Why my preferred_choices options select nothing when the form is construct ? I setting this with correct object setted previously in the code.

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $defaultCQSsearch = new CqsProSansMarque();
    $defaultCQSsearch->setRayLibelle((!array_key_exists('ray_libelle', $options['attr'])) ? null : $options['attr']['ray_libelle']);
    $defaultCQSsearch->setFamLibelle((!array_key_exists('fam_libelle', $options['attr'])) ? null : $options['attr']['fam_libelle']);
    $defaultCQSsearch->setCaeLibelle((!array_key_exists('cae_libelle', $options['attr'])) ? null : $options['attr']['cae_libelle']);

    $builder
        ->add('ray_libelle', 'entity', array(
            'class' => 'ApplicationDriveBundle:CqsProSansMarque',
            'data_class' => 'Application\DriveBundle\Entity\CqsProSansMarque',
            'property' => 'ray_libelle',
            'query_builder' => function(CqsProSansMarqueRepository $er){
                return $er->createQueryBuilder('a')
                ->select('a')
                ->groupBy('a.ray_libelle');
            },
            'preferred_choices' => array($defaultCQSsearch),
            'label' => 'rayon',
            'required' => false,
        ))
  • 写回答

1条回答 默认 最新

  • dpsyssiv90846 2014-11-22 16:27
    关注

    preferred_choices option expects an array of values but you are passing an array of object (i.e. $defaultCQSsearch)

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分