Routing bug (is it a bug?) |
[eluser]Référencement Google[/eluser]
I think this is a bug but that needs to be discussed. While using URI Segments to my functions, it's not working with custom routing. For you understand me, here is some tests: Without custom routing: Code: class Page extend Controller With a url like http://mysite.com/page/show/test it output "test" so that is correct. Now defining a custom route like that: Code: $route['page/:any'] = "page/show"; And calling the url like this: http://mysite.com/page/test Nothing is outputed. To make it work with routing, I have to make the controller like this: Code: class Page extend Controller In user guide I can read "Important: If you are using the URI Routing feature, the segments passed to your function will be the re-routed ones." So I think this is a bug. Can you confirm it?
[eluser]richthegeek[/eluser]
the URI segments are NOT passed to your function as arguments - you have to use the URI segment functions to retrieve these, as listed in the second block of code. I don't know if this is a bug or not - it certainly seems like something that could only happen by planning, and I can't see a guaranteeable way of passing the segments as arguments.
[eluser]richthegeek[/eluser]
I seem to remember that you can use regex routing (rather than keyword routing) to allow the sections to be passed as arguments.
[eluser]wiredesignz[/eluser]
In fact semgents ARE passed to functions by CodeIgniter by default, the uri->segment() method is only required if you use _remap() in your controllers. The OP has incorrect routes set up. Code: $route['page/:any'] = "page/show/$1"; // pass :any to page/show method.
[eluser]Référencement Google[/eluser]
The user guide example is: Code: $route['product/:any'] = "catalog/product_lookup";
[eluser]drfloob[/eluser]
The User Manual's URI Routing - Regular Expressions page has a decent backreference example, so you should start by rereading that section. But to really understand what's going wrong, read up on PHP's Regex Reference - Back References docs and preg_replace( ) function description. In short, to use backreferences in your routes, you need to include a capture group. Code: // notice the parenthesis around :any. That's a capture group.
[eluser]Référencement Google[/eluser]
You are absolutely right and, thanks to you Drfloob, that worked. It would be nice that the "Dereks" take a quick look at the user guide examples in the routing section because things are not very clear about this part and as you see that leads me to a problem.
[eluser]ptrippett[/eluser]
I believe the User guide needs updating with this information as the general examples do not show this functionality
[eluser]drfloob[/eluser]
I agree, the User Guide could use a few more simple regex/back-reference examples. The only example there now is a little complicated, and not very tantalizing to look at unless you already know some regex. Another paragraph and an example or two would probably do some good. But I don't think that the CI User Guide is the right place to host a common PHP Regex tutorial. If it could make a better case for "this is what a PHP back-reference can do in CI", regex newbs can search google for "php back-reference" and find everything they need to get up to speed
[eluser]ptrippett[/eluser]
There are so many forums and pages etc explaining regex's, PHP official site for example on ereg and preg. Putting a regex tutorial in the user guide would go off topic. But maybe here is a case for a code repository of commonly used code for use in CI. |
Welcome Guest, Not a member yet? Register Sign In |