形式/类型
class DemoType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', 'text');
}
// ...
}
控制器
$user = new User();
$form = $this->createForm(new DemoType(), $user);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->get('doctrine')->getEntityManager();
$em->persist($user);
$em->flush();
return // ...
}
}
看法
<form action="{{ path }}" method="post" {{ form_enctype(form) }}>
<div>
{{ form_widget(form.name) }}
</div>
{{ form_rest(form) }}
</form>
我想一次注册多个。
(最后我想在视图侧添加一个输入字段。(加号按钮等JavaScript))
一次注册两个或更多用户应该怎么做?