2 回答

TA贡献1811条经验 获得超4个赞
您已经通过 ajax 请求(id参数)中的查询字符串将参数传递给控制器,所以我假设您知道如何添加新参数,比如说type.
由于::class只返回一个具有完全限定类名的字符串,您可以使用这个新参数来构建您的FormType类并正常实例化它。如果请求的类型不存在,createForm将抛出InvalidArgumentException.
$ticketType = $request->query->get('type', ''); // Set 'main' type if not specified
$ticketFormType = 'App\Form\' . $ticketType . 'TicketType';
$ticket = new Ticket();
try {
$form = $this->createForm(TicketType::class, $ticket);
} catch (Symfony\Component\Form\Exception\InvalidArgumentException $e) {
// FormType doesn't exist
return new Response(null, 400);
}
return $this->render('ticket/select.html.twig', ['form' => $form->createView()]);
- 2 回答
- 0 关注
- 134 浏览
添加回答
举报