如何在symfony 3格式

时间:2016-08-10 02:25:36

标签: php doctrine-orm symfony symfony-forms

请问我怎样才能实现这一点。我有两个选择领域(实体),如类别和技能。我希望技能领域依赖于类别,即如果选择了一个类别,技能的选项应该是与该类别相关的技能,但如果没有选择类别,则该领域的选项应该是所有技能。

  

注意下面的代码仅用于说明目的

   public function buildForm(FormBuilderInterface $builder, array $options)
{


    $builder
        if ( a value is selected from
             (->add('category', EntityType::class, array(
            'class'=>'AppBundle:Category',
            'choice_label'=>'name'
             ))) )
        {
                present skills based on the selected category as

                ( ->add('skill', EntityType::class, array(
                    'class'=>'AppBundle:Skill',
                    'choice_label'=>'name',

                    'query_builder' => function (EntityRepository $er) {
                        return $er->createQueryBuilder('s')
                            ->select('s')
                            ->where('c = :category')
                            ->setParameter('category', $value selected from category);
                    },

                )))
}else{

 ->add('skill', EntityType::class, array(
    'class'=>'AppBundle:skill',
    'choice_label'=>'name'
    ))

}

1 个答案:

答案 0 :(得分:1)