CodeIgniter 输出类 - $this->output->set_content_type();

允许你设置页面的mime类型以便于输出 JSON , JPEG, XML 等类型的数据.[code]$this->output
->set_content_type(‘application/json’)
->set_output(json_encode(array(‘foo’ => ‘bar’)));

$this->output
->set_content_type(‘jpeg’) // 你也可以用".jpeg",它在查找 config/mimes.php 文件之前会移除句号
->set_output(file_get_contents(‘files/something.jpg’));[/code]重要: 确保你传递到此方法的非mime字符串在 config/mimes.php 存在,否则设置不起作用。

文章来源:http://cwiki.ossez.com/pages/viewpage.action?pageId=2392167