2016-12-06 2 views
2

슬림 프레임 워크와 Doctrine을 사용하고 있으므로 새 데이터를 성공적으로 삽입 할 때마다 json 응답을 반환하고 싶지만 모든 것이 작동합니다. 내 코드 :Slim Framework Doctrine json output

 $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. 내가 여기서 뭔가 잘못하고있는거야? 당신이 slim3 프레임 워크에서 작업하는 경우

답변

1

당신은 응답 withJson() 방법을 사용할 수 있습니다.

wihtHeader에 응답을 추가 할 수도 있습니다.

return $response->withStatus(200) 
      ->withHeader('Content-Type', 'application/json') 
      ->write(json_encode($person->getArrayCopy())); 
시도
관련 문제