set_content_type($mime_type[, $charset = NULL])
Parameters: |
|
---|---|
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.
1 2 3 4 5 6 7 | $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:
1 | $this ->output->set_content_type( 'css' , 'utf-8' ); |
Please login to continue.