douyin4875 2013-04-03 09:35
浏览 28
已采纳

在symfony中传递变量形式的builForm函数

I have tried this code in my controller

$form = $this->createForm(new CentrexEdit2Type($ids), $centrex);

I want now to add the ids form to my Form Builder:

     public function buildForm(FormBuilderInterface $builder, array $options)
        {
          $ids = $options['ids']; 
          .......

I failed on it Any ideas please?

Here I am joining the code:

   if ($step==2){
        $form = $this->createForm(new CentrexEdit1Type(), $centrex);
        $ids=$form->get('bases')->getData();
        }

        foreach($ids as $id){echo($id->getId());}
        if ($step==3){
         $form = $this->createForm(new CentrexEdit2Type(array('ids'=>$ids)), $centrex);
        }

I need $ids when $step==3, this is the problem.

  • 写回答

2条回答 默认 最新

  • douyi1963 2013-04-03 09:41
    关注

    what I do is create the form this way:

    $form = $this->createForm(new TheForm($anArray), $client);

    where $anArray is an array.

    Then, in the form I do something like:

    public $anArray;
    
    public function __construct($anArray)
    {
        $this->anArray = $anArray;
    }
    

    after this, inside the form class I access the array with $this->anArray

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写