• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incorrect handling of 404?

Good morning, fellas.

I've been noticing a strange behavior in the way that CodeIgniter handles the 404 error (since it's kind of a "special" error).

Suppose I have 2 controllers: login (with methods index, create and validate) and notifications (with methods index and missing). In the routes.php, my 404_override is "notifications/missing". If I enter in the url http://example.com/loginssads/someurl (a controller that doesn't exists), the proper controller and method loads.

But, if I enter http://example.com/login/adsadsads (a controller that does exists, but a method that doesn't) then the errors/error_404.php template loads, NOT my custom 404 page.

Is this a bug? I think that the 404_override is missing something.

Also, there's no documentation about the variables available inside the errors folder (like $heading), not what can I use (I don't know if that's a view, or something).

Any help about this issue is greatly appreciated.

Are you using CI 1.7.x or 2.0?

I'm using Codeigniter 2.0 - I don't remember seeing that configuration variable in 1.7.x, though.

I'm using 2.0 and was able to replicate what you were talking about. I did some googling to see if anyone else has reported a problem like this.

I found this article: http://bit.ly/giOnkl which seems to confirm our findings that it only applies if there is no controller found but offers a path to a solution.

Thank you for your response. I'm getting what the author meant in the post (and I shall try it) - but according to this: http://bit.ly/i0xdu3 the bug has already been fixed. I will try with that release and report back.

ok, cool. let me know how it goes. i may have to do some updating as well. Smile

I've been testing that Reactor change, and I've come to realize it's behavior:

When updated to Reactor, if you set "404_override" to a single controller (for example, $route['404_override'] = 'missing'Wink THAT EXISTS it will send you directly to the index method of that controller.

When set to a single controller that DOESN'T EXISTS, it will throw a PHP error.

This is where it gets interesting: If you set a double route (controller/method), it will check if the controller (defined in the routes.php file) exists, THEN OVERRIDE IT and look for the method you defined inside the controller THAT IS BEING SHOWN in the URL. e.g if you have 404_override = 'something/missing' and controller "something" exists, and you call "login/dasassadads", then the "login/missing" method will load instead.

Finally, if you set a double route and the controller does NOT exists, it will give you an error, looking for a "missing" method inside the controller you defined.

That's all I know. Perhaps it could be modified (since there's some fine feedback in BitBucket), or it could just be used like it's working.

My suggestion? Create an independent controller that ONLY handles 404 errors. If you add a method, chaos may break loose.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.