0

这是我的表单代码:

 class CentrexEdit1Type extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {       
            $builder          
                ->add('bases', 'entity', array(
                  'class'    => 'TelnOperatorBundle:Base',
                  'property' => 'name',
                  'multiple' => true,

                ));
            $ids= $builder->getData()->getBases();  

        }

        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'Teln\OperatorBundle\Entity\Centrex'
            ));
        }



        public function getName()
        {
            return 'teln_operatorbundle_centrextype';
        }   

    }

我需要将变量$ids= $builder->getData()->getBases();从“CentrexType”传递给控制器​​。我应该使用服务吗?我尝试了 getSession 但失败了。怎么做?

示例:我必须在其中添加 query_builder

class CentrexEdit2Type extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {


    $builder->add('softswitchs', 'entity', array(
              'class'    => 'TelnOperatorBundle:Softswitch',
              'property' => 'name',
              'multiple' => true,
              'query_builder' => function(\Teln\OperatorBundle\Entity\SoftswitchRepository $er) use ($ids)
                                         {

                                        $identities=array();
                                        foreach($ids as $id){
                                        $identities[]=$id->getId();
                                        }
                                         $qb = $er->createQueryBuilder('t')
                                                  ->where('t.base IN(:ids)')
                                                  ->setParameter('ids', $identities); 

                                          return $qb;

                                          },
               ));


    }
4

0 回答 0