Pop\Mvc\Controller::sendJson PHP Method

sendJson() public method

Method to send a JSON response
public sendJson ( mixed $values, integer $code = 200, array $headers = null ) : void
$values mixed
$code integer
$headers array
return void
    public function sendJson($values, $code = 200, array $headers = null)
    {
        // Build the response and send it
        $response = new Response();
        $this->response->setCode($code);
        if (null !== $headers) {
            foreach ($headers as $name => $value) {
                $this->response->setHeader($name, $value);
            }
        }
        // Force JSON content-type header
        $response->setHeader('Content-Type', 'application/json')->setBody(json_encode($values));
        $response->send();
    }