The examples I see are suggesting the use like this:
$response = new Response();
echo $response->body($view)->send_headers()->body();
But if I have the following code
$response = new Response();
$response->headers('Content-Type', 'application/json');
echo $response->body($view)->send_headers()->body();
it sends the output allright, but it is in HTML format, not JSON.
Whats the valid way to send a new Response along with headers then? I am using Kohana 3.1 with php 5.3
Edit:
Before you start thinking what a fool I am for not using $this->response->body(<blah here>);, let me clarify that I know how to use the controller’s response object… That is not what I am looking for… I want to send a response entirely from a static function that is not anywhere near a controller in the function call stack 🙂
OK, after scratching my head and attempting many solutions, I decided to use this:
Request::initial()->response()
->body($view)
->headers('Content-type','application/json');
Works from anywhere unless you write
exitsomewhere in the flow.