【问题标题】:Slim Framework Doctrine json outputSlim 框架原则 json 输出
【发布时间】:2016-12-06 04:45:42
【问题描述】:

所以我使用的是 Slim Framework 和 Doctrine,虽然我想在成功插入新数据时返回一个 json 响应,但一切正常。我的代码是:

        $now = new \DateTime('now');
        $people->setCreatedOn($now);
        $people->setModifiedOn($now);

        $people->setCreatedBy($this->engine->getCurrentUser()->getUserId());
        $people->setModifiedBy($this->engine->getCurrentUser()->getUserId());


        $this->em->persist($people);
        $this->em->flush($people);

        $person = $this->em->getRepository('App\Entities\EibPerson')->findOneBy(array('personId' => $people->getPersonId()));
        return $response->withJSON($person->getArrayCopy());

虽然我没有看到任何响应 json,但数据已成功插入。我在这里做错了吗?

【问题讨论】:

    标签: php json symfony doctrine-orm doctrine


    【解决方案1】:

    如果您在 slim3 框架中工作,您可以使用带有响应的 withJson() 方法。

    您也可以尝试在回复中添加wihtHeader

    试试这个

    return $response->withStatus(200)
                ->withHeader('Content-Type', 'application/json')
                ->write(json_encode($person->getArrayCopy()));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      相关资源
      最近更新 更多