Symfony2.1 using form with method GET

痴心易碎 提交于 2019-11-28 09:24:38
Bernhard Schussek

You can set the name of the root form to empty, then your field name will be just form. Do so via

// the first argument to createNamedBuilder() is the name
$form = $this->get('form.factory')->createNamedBuilder(null, 'form', $defaultData)
    ->add('from', 'date', array(
        'required' => false,
        'widget' => 'single_text',
        'format' => 'dd.MM.yyyy'
    ));

old thread, but worth mentioning that symfony 3 ignores getName entirely.

However, you can do the same with getBlockPrefix if you need the form name to be blank.

public function getBlockPrefix() {
    return null;
}

this will result in form fields being named without a prefix.

using return null; in your implementation of AbstractType::getName seems to have the same effect these days.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!