douxianxing5712 2014-07-22 10:12
浏览 48
已采纳

Symfony返回表格字段

I would like to create a function which returns a form field that can then be added to a form. Currently I have something like:

$builder->add($name,$type,$options);

I would like something similar to:

function getField()
{
    //$name, $type, $options = blah

    $builder = $this->createFormBuilder();
    $builder->add($name,$type,$options);
    return $builder;
}

$field = getField();
$builder->add($field);
  • 写回答

1条回答 默认 最新

  • douya2982 2014-07-22 11:36
    关注

    You should only create one FormBuilder per Form. Your issue could be solved by passing the FormBuilder instance to the the function that generates the field:

    function addField($builder)
    {
        //$name, $type, $options = blah
    
        $builder->add($name,$type,$options);
    }
    
    $builder = $this->createFormBuilder();
    
    addField($builder);
    

    Does this meet your requirements?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效