du8791069 2016-06-30 10:34
浏览 66

如何在php代码中使用POST请求在collection.create上设置模型属性?

i don't know how to handle the request in my controller in symfony in the php code. So im creating a new model in my collection with collection.create() method but I don't know how to handle it in symfony php code. Can anyone help me?

Collection.create() code:

save: function()
    {            
            this.collection.create({
                    title: $("#title").val()
            });
            console.log(this.collection);
    }

PHP code:

/**
     * @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);
}

Request method: POST, status: OK

enter image description here

  • 写回答

1条回答 默认 最新

  • duanjie1339 2016-06-30 10:41
    关注

    May be you forget to set the properties on the Document object

    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);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分