How to define content-type with Code Igniter REST_Controller

10,736

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)

Share:
10,736
ChickensDontClap
Author by

ChickensDontClap

Updated on June 05, 2022

Comments

  • ChickensDontClap
    ChickensDontClap almost 2 years

    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?