Custom 404 control |
[eluser]DieterStruik[/eluser]
Hi CI-ers, You probably ran across the same problem like me. Trying to avoid the standard 404 page which doesn't include all the CI functionality. Therefore making weird includes, cURL calls etc... I make use of a language segment in my URI's. Like /en/home. So I needed to route like: Code: $route['default_controller'] = 'site'; You don't need to change any existing functionality. Put this code below in any controller (I usually extend my main controller). It's the native _remap() method which always get called first. Here you can check stuff like a missing method. Code: public function _remap($method) I hope this will be usefull for some of you. I haven't checked it for different types of errors. Just thought about a missing method call. Please let me know anything better.
[eluser]davidbehler[/eluser]
But that only accounts for nonexistent methods. What about nonexistent controllers?
[eluser]DieterStruik[/eluser]
Hi, you're right. That still is a problem. I Guess some trick needs to be done first.
[eluser]DieterStruik[/eluser]
Hi Waldmeister, So... first time no success on missing controllers. How about this: 1) Modify the CI error_404.php by replacing the content with: Code: <?php Ofcourse /nl/site/error404 is an existing method of my catch all controller named Site. 2) Add the following code in the catch all controller from my first post. Code: public function error404()
[eluser]louis w[/eluser]
Why would you have to use curl inside of the built in 404 page? Another possible solution would be my proposed addition of a _default built in method. At the core level, it's functionality is the same as what you outlined above but it would be a native feature and would not require using _remap to catch everything. For non existant controllers, it would/should call the default controller's _default method.
[eluser]DieterStruik[/eluser]
Hmmm... for better understanding it's better to clean things up in clear steps. STEP 1: routes.php Code: $route['default_controller'] = 'firstcontroller'; STEP 2: The extended controller or method in every controller Code: public function error404() STEP 3: Replace contents of the error_404.php Code: <?php
[eluser]louis w[/eluser]
Another possible solution would be to edit the error_404.php error page to load your custom view. I have done this on a view projects. Code: <?php header("HTTP/1.1 404 Not Found");
[eluser]Madmartigan1[/eluser]
@louis: When will get_instance() or the loader class ever be available to the error page? As far as I know, only config, hooks, and router are loaded at this point. Please explain how you got this to work. EDIT: Nevermind :-P
[eluser]SitesByJoe[/eluser]
I'm dealing with this right now too. I'm finally ready to move past the default CI 404 page. I'l post my solution shortly. (I hope!)
[eluser]SitesByJoe[/eluser]
Louis W's solution did the trick, but I can't seem to get it working quite right yet. |
Welcome Guest, Not a member yet? Register Sign In |