将变量从from传递给控制器​​symfony2

时间:2013-04-03 08:40:12

标签: php symfony

以下是我的表格代码:

 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;

                                          },
               ));


    }

0 个答案:

没有答案