rodriguez
rodriguez

Reputation: 35

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:

  1. Why is the JSON data from the server being displayed together with the text in my renderText() method?

  2. Where is the '1' appended to the JSON data coming from?

  3. How do I resolve/fix this issue ?

I am running Symfony 1.4.x on Ubuntu

Upvotes: 2

Views: 7267

Answers (1)

Maerlyn
Maerlyn

Reputation: 34107

From the looks of it, your problem lies in getServerResponse(). Can't help more without seeing that function.

Upvotes: 2

Related Questions