snapper 0 Posted July 3, 2013 Report 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 Quote Link to post Share on other sites
Larry 428 Posted July 3, 2013 Report 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. Quote Link to post Share on other sites
snapper 0 Posted July 5, 2013 Author Report 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. Quote Link to post Share on other sites
Larry 428 Posted July 5, 2013 Report 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.