wobsoriano
wobsoriano

Reputation: 13434

Slim Framework Doctrine json output

So I am using Slim Framework and Doctrine, everything is working though I want to return a json response whenever I successfully inserted new data. My code is:

        $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());

Data is successfully being inserted though Im not seeing any response json. Am I doing something wrong here?

Upvotes: 2

Views: 187

Answers (1)

Gopal Joshi
Gopal Joshi

Reputation: 2358

If you are working in slim3 framework you can use withJson() method with response.

You can also try adding wihtHeader with response.

Try This

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

Upvotes: 1

Related Questions