Javascript 如何在php代码中使用POST请求设置collection.create的模型属性?
我不知道如何在php代码中用symfony处理控制器中的请求。所以我用collection.create()方法在我的集合中创建了一个新模型,但我不知道如何在symfony php代码中处理它。有人能帮我吗 Collection.create()代码: PHP代码:Javascript 如何在php代码中使用POST请求设置collection.create的模型属性?,javascript,php,backbone.js,symfony,Javascript,Php,Backbone.js,Symfony,我不知道如何在php代码中用symfony处理控制器中的请求。所以我用collection.create()方法在我的集合中创建了一个新模型,但我不知道如何在symfony php代码中处理它。有人能帮我吗 Collection.create()代码: PHP代码: /** * @Route("/document") */ public function createAction(Request $request) { $content = $reque
/**
* @Route("/document")
*/
public function createAction(Request $request)
{
$content = $request->getContent();
$document = new Document();
$em = $this->getDoctrine()->getManager();
$em->persist($document);
$em->flush();
return new JsonResponse($document);
}
请求方式:POST,状态:OK
您可能忘记设置文档对象的属性
public function createAction(Request $request)
{
$document = new Document();
我不知道您的文档实体属性是什么,这只是一个示例。在文档实体中,我有id、标题、文档和用户id。以及set和get方法。好的,您能在浏览器调试中显示请求的post参数吗?您是指请求负载吗?是的。。。请原谅我英语不好
public function createAction(Request $request)
{
$document = new Document();
$document->setTitle($request->get('title'));
$em = $this->getDoctrine()->getManager();
$em->persist($document);
$em->flush();
return new JsonResponse($document);
}