CodeIgniter Forums
redirect not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: redirect not working (/showthread.php?tid=33766)



redirect not working - El Forum - 09-07-2010

[eluser]seonghuhn[/eluser]
I'm a newbie to CodeIgnitor and I'm afraid this question might be a little naive. Nevertheless...

I have a form which correctly calls my email function in my controller which is called Coupon.

At the end of this function I want to redirect back to the index page. But it never does though I tried:

redirect('coupon');

redirect('coupon/');

redirect('coupon/index');

redirect('coupon/index/');

redirect('/');

As added information coupon is configured as my default controller in routes.php.

I am pretty confused since my application so far is very simple and is basically a copy of the video tutorial.

Your help would be most appreciated. :-)

Thanks,
Frank


redirect not working - El Forum - 09-07-2010

[eluser]bretticus[/eluser]
redirect() calls php's native header() function. It is IMPERATIVE that headers have not been sent already. In other words, make sure you are not sending any output before calling redirect.


redirect not working - El Forum - 09-07-2010

[eluser]seonghuhn[/eluser]
Thanks for the help.

I don't have a view associated with this email method. In fact now I have the method doing _nothing_ except redirect and it is still not redirecting. And the page is completely blank, absolutely no HTML.


redirect not working - El Forum - 09-07-2010

[eluser]bretticus[/eluser]
Doesn't mean there's not output higher up (can go all the way to index.php really.) Try checking for sent headers with headers_sent().


redirect not working - El Forum - 09-07-2010

[eluser]seonghuhn[/eluser]
I'm an idiot. I forgot to load the URL helper. Thanks!


redirect not working - El Forum - 09-07-2010

[eluser]seonghuhn[/eluser]
I'm surprised I didn't see any errors anywhere about my not loading the URL helper, i.e. the redirect method not being found.


redirect not working - El Forum - 09-07-2010

[eluser]bretticus[/eluser]
[quote author="seonghuhn" date="1283938264"]I forgot to load the URL helper.[/quote]

Or that! Smile