Why can't I use helper functions in custom 404 pages? |
[eluser]KeyStroke[/eluser]
Hi, I'm trying to make my own error page by replacing the one in the "application/errors" directory. The problem is, whenever I use a URL helper (like base_url()), I get the following error: Quote:Fatal error: Call to undefined function base_url() in X:\my_app\system\application\errors\error_404.php on line 6 Why can't I use them? and how do I work around this? Your help is much appreciated
[eluser]TheFuzzy0ne[/eluser]
A lot of the time a 404 is thrown before a lot of the base classes have loaded. If your controller has loaded, you should be able to do: Code: $CI =& get_instance(); from inside the view, but it won't help for errors that are thrown before the base classes and functions are loaded. The error page is shown with a simple call to include(), it's not loaded within the scope of CodeIgniter like other views. I highly recommend you make your error pages static, as you won't know what's been loaded and what hasn't been, and if a function you are calling upon within your error page is not available, then your error page will also be broken, and there's no page to show errors about error pages. ![]() My Error page looks similar to the rest of the site, but it doesn't contain any dynamic information, such as username, login, logout etc, as there's consistent way to check this information. Another option might be to just have a simple message appear on the page, telling the user to use their back button to go back a page. Hope this helps, even if it's not the answer you were looking for.
[eluser]KeyStroke[/eluser]
Thanks TheFuzzy0ne. ![]() The problem is, in my errors pages, I have dynamic elements such as the navigation of the site, and the inclusion of the header/footer. It wouldn't be practical at all to keep changing those manually every time I change something in the site. So, what do you (or anyone else) suggest?
[eluser]TheFuzzy0ne[/eluser]
Having a simple message on a neatly designed page (just a simple box would do), telling your user the page doesn't exist and advising them to click on the back button, should work fine. It's simple, and like most simple ideas, it just works. The dynamic elements are only but a back button click away.
[eluser]vitch[/eluser]
I just wrote up the method that I use for custom 404 error pages on my site - maybe it will help you: http://www.kelvinluck.com/2009/04/custom...deigniter/ Cheers, Kelvin ![]() |
Welcome Guest, Not a member yet? Register Sign In |