symfony2 form how to accept json payload from angular resource

限于喜欢 提交于 2019-12-06 13:26:11

I finally found a solution, after reading deeper in the documentation. Symfony\Component\Form\Form::bind doesn't require a Request, it works with an array too. so here's my Solution (the sloppy way, would need some checking of the header, etc. for production use..)

public function setFooAction(Request $request){

  $form = $this->createForm();//get the form class, etc...
  $json_data = json_decode($request->getContent(),true);//get the response data as array
  $form->bind($json_data); //Bind data to Form

  if ($form->isValid()) {
    ...

  }

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