[CI3] - URI class returning Controller name in ucfirst |
Hi everyone,
it seems there's a little problem with 404-errors management in the main CodeIgniter class. Between the lines 429 and 478 of the CodeIgniter.php file, there's the following statement : PHP Code: if ($e404) Basically, at some point here, the Controller class that is stored as the first rsegments index of the URI class is stored in ucfirst. And it seems this is the only point in CI where it's not stored in lowercase. So what's my problem here ? I've got (on a previously designed application i'm working on) a 404 override route defined on my routes.php config files, as follows : PHP Code: $route['404_override'] = 'home/page404'; Normally it wouldn't be a problem, but that Controller "Home" also handles the application login process. So, in my CI_Controller core override, i've got the following statement : PHP Code: if($this->check_logged_in()) { So what i'm basically doing here is just check that the user is correctly logged in, or else redirect him to the default login page only if we're not on the "Home" Controller or already on the login page. What i end up with here is : if the user isn't logged in and try to access a non-existing page of my website, he should see a 404 page. But instead of that, i end up with the previous statement ($this->uri->rsegment(1) != 'home') evaluated to TRUE; because in that case, the rsegment returned by the URI Class is "Home", not "home". Thus the user is redirected on the login page, and never sees the 404 page... So, while i must admit this is not trully horrible for the user in the end (or that i could handle it myself by manually applying a simple strtolower() on the return value of the rsegment() method), i feel like it shouldn't work that way, thus the reporting...
Can't you just use
PHP Code: $this->uri->segment(1) PHP Code: $this->uri->rsegment(1)
This is the indended behavior ... the fact that this is the only place the controller name is stored in Ucfirst inside the URI class is simply because that's the only place it stores an actual controller name.
You can either apply strtolower() or just compare against 'Home' instead of 'home'. (09-23-2015, 07:30 AM)Martin7483 Wrote: Can't you just use Actually, he can't. It's a 404 override ... that's pretty much the only place segment(1) is guaranteed not to match rsegment(1).
Thanks for the quick answer Narf. This is exactly what i was looking for : whether it is an intended behavior or not. So, as we both said, i'll handle this special case with a strtolower().
|
Welcome Guest, Not a member yet? Register Sign In |