Question

In one of my action I use forwarding to get data from other controller:

$collect = ($this ->forward('MyPracticeBundle:Collect:collect', array('jid' => 1, 'rid' => $rid)));

The collectAction in CollectController would return an json response:

return new response(json_encode(array("havecollect" => 0)));

And now I want to get those data from other controller, I tried:

$collect = json_decode($collect);

But that won't work, What should I do to handle this problem?

Was it helpful?

Solution 2

Just add ->getContent()behind my response, and use $collect = json_decode($collect, true); instead, it would work.

OTHER TIPS

Because you're not getting JSON as a result from forward method but symfony response object. Furthermore, guessing from your code snippets, you're trying to do a very bad thing.

If you want one action to collect data and return it in JSON format while other does something else to that data, you should make a method in your service layer which retrieves that data and use it in both actions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top