CI_Output::set_content_type PHP Method

set_content_type() public method

Set Content-Type Header
public set_content_type ( string $mime_type, string $charset = NULL ) : CI_Output
$mime_type string Extension of the file we're outputting
$charset string Character set (default: NULL)
return CI_Output
    public function set_content_type($mime_type, $charset = NULL)
    {
        if (strpos($mime_type, '/') === FALSE) {
            $extension = ltrim($mime_type, '.');
            // Is this extension supported?
            if (isset($this->mimes[$extension])) {
                $mime_type =& $this->mimes[$extension];
                if (is_array($mime_type)) {
                    $mime_type = current($mime_type);
                }
            }
        }
        $this->mime_type = $mime_type;
        if (empty($charset)) {
            $charset = config_item('charset');
        }
        $header = 'Content-Type: ' . $mime_type . (empty($charset) ? '' : '; charset=' . $charset);
        $this->headers[] = array($header, TRUE);
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 private function processResponseData(array $response)
 {
     if (!$this->input->is_ajax_request()) {
         redirect('/');
     }
     $this->output->set_content_type('application/json');
     if ($response['code'] == 200) {
         if ($response['data']['success']) {
             $this->output->set_output(json_encode($response['data']['data']));
         }
     }
 }
All Usage Examples Of CI_Output::set_content_type