set_content_type() Doesn't seem to be working? |
Hey guys, im trying to set the header type on a page, heres the code, pretty basic:
PHP Code: public function current() It doesnt at all change the header, however if I change it to this: PHP Code: public function current() It works fine. I dug through the Output.php file, and notice on line 467, you disable the errors of the header() function by using a @, if I take that out, I get the error.. Quote:Message: Cannot modify header information - headers already sent by (<MY FILE:LINE>) So is there a reason the set_content_type() is executing after the page output?
Well... you did the echo $partition inside a controller.... You should use $this->load->view('your_view'); and put that echo inside the view.
Website: http://avenir.ro
Yes, you need to use a view, OR use set_output() because of the way CI buffers output. If you echo from a controller, that happens before anything else since the controller has to complete before CI will send IT's data out. And using output->set_content_type() is part of that, which is why it doesn't work the way you wrote it and using native PHP header() does.
A workaround is to finish what you started and send your output using output->set_output() http://www.codeigniter.com/user_guide/li...set_output $this->output->set_output($partition); //instead of echo $partition |
Welcome Guest, Not a member yet? Register Sign In |