Welcome Guest, Not a member yet? Register   Sign In
Spicing up error pages (404, DB, etc)
#1

[eluser]ejangi[/eluser]
I'm not a big fan of presenting a site visitor with "brick-walls" (pages that don't go anywhere), so I'm trying to find a way to make the show_404() pages display views and generally access the CI singleton (get_instance()).

For instance, in my views I have a "sitemap" which calls helper functions like base_url() and anchor(), but if I include() this file in the /errors/error_404.php file, PHP complains that it doesn't know what the base_url() function is, etc... This is of course, because the error_404.php file is a stand-alone PHP file (with no access to CI_Base).

I understand (looking at the core) why the exception handling is built the way it is, it's just not ideal for what I need.

SO... My question is: Has anyone found an elegant solution for dealing with this?
#2

[eluser]Sarre[/eluser]
How about using a header redirect in that error_404.php file?
That way you can redirect to whatever controller you wish...

So change
Code:
header("HTTP/1.1 404 Not Found");
into
Code:
header("location:http://url");
It's probably not the best (most CI) way of doing it, but it works.
#3

[eluser]t'mo[/eluser]
[quote author="ucantblamem" date="1199355799"]...my views I have a "sitemap" which calls helper functions like base_url() and anchor(), but if I include() this file in the /errors/error_404.php file, PHP complains that it doesn't know what the base_url() function is, etc... This is of course, because the error_404.php file is a stand-alone PHP file[/quote]

I was just reading an article about this very topic (http://www.rfinteractive.com/rfi-blogs/l...-foun.html) and wondered how I'd build the same sort of thing. When you get an answer to an "elegant" solution, I'd like to hear about it too. :-)
#4

[eluser]Aea[/eluser]
Okay, take this with a grain of salt since my experience is limited.

Create a new controller for all error messages, log messages, etc. Then you can make it as advanced as possible, including redirects, descriptive text, etc. Redirect the regular error messages to that controller. Probably would be more elegant to extend the current error system.
#5

[eluser]Tom Glover[/eluser]
One way is to move your error 404 pages into CI then get htaccess to redirect errors to the controller. This would allow you to use any CI feature in your error pages.




Theme © iAndrew 2016 - Forum software by © MyBB