Displaying a 404 if wrong number of segments passed to controller function? |
[eluser]Unknown[/eluser]
Hello, I have a question about handling unexpected URL segments and showing errors. For example: given a URL that resembles /controller_class/function/variable, I was expecting CodeIgniter to display a 404 if the function does not except a parameter. Or, more generally, I would expect that if the number of URL segments is greater than the number of parameters for the given function, that the URL is not valid and should display an error to the user. Since no error is given, is there a way to check for such a condition that doesn't involve checking the parameters on a per-function basis? That could get repetitive. I haven't worked with PHP5 enough to know about the Reflection APIs but my understanding is that there's a way to check on the number of parameters of a Class' method... ... or perhaps I've just overlooked something obvious. Any insight would be appreciated. Thanks!
[eluser]theprodigy[/eluser]
using a _remap function can help in this situation. Code: public function _remap($method, $params = array())
[eluser]John_Betong_002[/eluser]
>>> ... or perhaps I’ve just overlooked something obvious. Any insight would be appreciated. Thanks! http://ellislab.com/codeigniter/user-gui...uting.html First try routing all your anticipated URLs. Followed by a catchall: Code: // default route
[eluser]Unknown[/eluser]
[quote author="theprodigy" date="1306474024"]using a _remap function can help in this situation. Code: public function _remap($method, $params = array()) Just what I was looking for. Awesome. |
Welcome Guest, Not a member yet? Register Sign In |