Symfony action with json response
I am using PHP + CURL to fetch data from a server in one of my actions. I then return the data as json from my action.
My action looks like this
public function executeTest(sfWebRequest $request)
{
$json = $this->getServerResponse(); // fetches data using CURL
$this->getResponse()->setContentType('text/json');
return $this->renderText($json);
}
When the above action is executed, the received json strng is (for example):
{ 'ok': true }1
If I change the last line in the action above to return $this->renderText('foo');
the returned JSON is:
{ 'ok': true }foo
If I change the last line in the action above to return $this->renderText('');
the returned JSON is:
{ 'ok': true }
My question are:
Why is the JSON data from the server being displayed together with the text in my renderText() method?
Where is the '1' appended to the JSON data coming from?
How do I resolve/fix this iss开发者_StackOverflow社区ue ?
I am running Symfony 1.4.x on Ubuntu
From the looks of it, your problem lies in getServerResponse()
. Can't help more without seeing that function.
精彩评论