snapper Posted July 3, 2013 Share Posted July 3, 2013 When a user clicks a button in my application, it is supposed to reroute them to a certain page in my application, but instead I get the following error message: Cannot modify header information - headers already sent by (output started at /home/colly/public_html/myapp/ItemsController.php:218) and here is the function inside of the itemsController that generates the error: public function actionRedirectSomewhere($itemId) {$this->redirect(array('items/index'));} It still gives me the same error if I call the function without the parameter like this: actionRedirectSomewhere() {$this->redirect(array('items/index'));} I am not aware of any headers that I am sending. How can I fix this error? Any help would be appreciated. //snapper Link to comment Share on other sites More sharing options...
Larry Posted July 3, 2013 Share Posted July 3, 2013 What is line 218 of ItemsController.php? It's not a matter of sending headers that's causing the problem exactly, it's that the browser has already received some data, such as HTML or even a blank space, which means the redirect cannot occur. Link to comment Share on other sites More sharing options...
snapper Posted July 5, 2013 Author Share Posted July 5, 2013 Here is line 218: public function actionRedirectSomewhere($itemId) {$this->redirect(array('items/index'));} It's the function call with the redirect statement. You were right. I was getting this error because I omitted the closing php tag at the end of the ItemsController. I was told I should do that (omitting closing php tags) but did not understand when, why and where I should omit this ?> if at all. Link to comment Share on other sites More sharing options...
Larry Posted July 5, 2013 Share Posted July 5, 2013 You should omit the PHP closing tags in scripts that are included by other scripts such as class definition files. You don't omit the closing PHP tags in view files, though. Link to comment Share on other sites More sharing options...
Recommended Posts