tombenner/wp-mvc

Recommended way to return a JSON

ivamluz opened this issue · 4 comments

In case I create an action that returns either HTML or JSON (depending on the content-type header), is there a recommended way to return JSON content?

Should I create a view that is responsible for encoding the data as JSON or is there any method in the controller that can be called directly to return JSON, instead of setting a parameter in the view?

@cyberscribe How to you set the content type header? Having no luck on setting it.

header('Content-type: application/json'); echo json_encode([]); die();

@cyberscribe Very nice framework, I will use it to implement a Product Catalog CMS. Thank you.