We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Blank response

HI, I'm trying to implement a REST api using the mvc pattern. I edited the example on github https://github.com/phalcon/mvc/tree/master/simple-subcontrollers, where I removed the views and everything linked to volt, thus having a kind of MVC without 'V', since I'm returning json objec "(json encode)", but having a blank answer. What could be the problem ?

Did it work with views prior to you removing them?

is your htaccess file set properly?

So many possible issue, so little time :)

It could be so many things.

edited Dec '16

Some exception or fatal error. Don't use json encode. Use this:

return $this->response->setJsonContent(['asd' => 'xyz']);


8.0k
Accepted
answer

The problem was with the controller. I didn't add a controller for index, after adding I was able to get the json result.

I tend to recommend framework's methods by default, but with this method we had issue with jQuery. The thing cannot read response if you use Phalcon method and Response obj, but only with json_encode.

Per standrds, Phalcon does the good job here with 3.0.x stack as it sets Content Type to application/json (with UTF-8 encoding which is not required).

Some exception or fatal error. Don't use json encode. Use this:

return $this->response->setJsonContent(['asd' => 'xyz']);