route annoyance |
[eluser]HdotNET[/eluser]
Hi all, The routes system is driving me up the wall. I'm sure its down to me, but would appreciate another set of eyes on this... Routes file: Code: $route['pages/:num'] = "cmspages/viewpage"; The cmspages controller is, um, a cms. The index method within the controller looks at all the uri segments in order to retrieve a page/provide a 404, perfectly handled by the :any route directive as shown above. Controller: Code: class Cmspages extends Controller { The problem I am having is with the first pages/:num directive. The second uri segment (:num) should surely be passed as a param to the viewpage function in the controller and then echo'ed? It isn't. This doesn't work either (no numeric param passed): Code: $route['pages/viewpage/:num'] = "cmspages/viewpage"; Neither does this: Code: $route['cmspages/:num'] = "cmspages/viewpage"; This DOES work as expected, but doesn't give the desired urls: Code: $route['cmspages/viewpage/:num'] = "cmspages/viewpage"; Can anyone tell me what is wrong with this picture? Naturally I could use the URI object to get the desired param, but judging by the docs I shouldn't need to: URI Routing Quote:Wildcards
[eluser]deviant[/eluser]
Are you sure it passes the wildcard as a function argument?
[eluser]HdotNET[/eluser]
Er no. I'm not entirely sure, but if it doesn't then it should! At least I haven't used this framework enough to see why it shouldn't.
[eluser]deviant[/eluser]
Well from what I read in the docs it doesnt say anything about passing it as an argument, so you might have to use regex instead to pass the value you want as a URI segment and get it that way.
[eluser]HdotNET[/eluser]
this works like I expected $route['pages/:num'] should: Code: $route['pages/(\d+)'] = "cmspages/viewpage/$1"; thanks deviant...
[eluser]frenzal[/eluser]
yep that'll do the trick or you can just use $this->uri->segment(x)
[eluser]HdotNET[/eluser]
true but the regex does the work of ensuring that the retrieved param is a number and that additional url params cannot be parsed to the function.
[eluser]andho[/eluser]
if that happens i think you have to use a non-greedy regex: $route['pages/(\d+?)'] = "cmspages/viewpage/$1"; regex is a whole other world. and its hard to get there |
Welcome Guest, Not a member yet? Register Sign In |