CI_Output::set_content_type()

set_content_type($mime_type[, $charset = NULL])

Parameters:
  • $mime_type (string) – MIME Type idenitifer string
  • $charset (string) – Character set
Returns:

CI_Output instance (method chaining)

Return type:

CI_Output

Permits you to set the mime-type of your page so you can serve JSON data, JPEG’s, XML, etc easily.

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

$this->output
        ->set_content_type('jpeg') // You could also use ".jpeg" which will have the full stop removed before looking in config/mimes.php
        ->set_output(file_get_contents('files/something.jpg'));

Important

Make sure any non-mime string you pass to this method exists in application/config/mimes.php or it will have no effect.

You can also set the character set of the document, by passing a second argument:

$this->output->set_content_type('css', 'utf-8');
doc_CodeIgniter
2016-10-15 16:31:48
Comments
Leave a Comment

Please login to continue.