Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define content-type with Code Igniter REST_Controller

I'm working with the REST_Controller extended CI_Controller and for some reason my requests are all coming back with a content-type of text/html instead of json. In my config, I have json set as the default format:

$config['rest_default_format'] = 'json';

My results are coming back as JSON, but the content-type isn't being set. Can anyone help with what I'm missing?

like image 582
ChickensDontClap Avatar asked May 31 '12 20:05

ChickensDontClap


1 Answers

I'm not sure if the config sets the format. But a simple work around might be just to use the output class to set the header content type, something like:

$this->output
    ->set_content_type('application/json')
    ->set_output(json_encode(array('foo' => 'bar')));

(Taken from the manual: here)

like image 186
Ben Avatar answered Sep 22 '22 01:09

Ben