Welcome Guest, Not a member yet? Register   Sign In
Routes: how to get mycontroller/id function same as mycontroller/action/id
#6

[eluser]Majd Taby[/eluser]
Here's a conversation that happened in the irc channel (#codeigniter on irc.freenode.net), thought it would help clear things up:

Quote:<1 - needs help> man it must just be me, but ive never gotten even the simplest routes to work
<1 - needs help> $route["org/[0-9]"] = "org/index/$1"; ... for example
<2 - helping> $route['(org/[0-9]+)']
<2 - helping> possibly
<2 - helping> you gotta have parenthesis
<1 - needs help> aha!
<1 - needs help> funny none of the docs i found use those
<1 - needs help> but yet it works now
<1 - needs help> oops nm no it doesnt
* fio__ ([email protected]) has left #codeigniter
<1 - needs help> do i have to have function index() or function index($id=0) in my controller?
<2 - helping> neither will work in CI (because CI's routing is busted)
<2 - helping> you need $this->uri->rsegment(1)
<2 - helping> or similar
<1 - needs help> hmm, but ... if you come to the page as controller/index/id ... its segment(3) ... whereas ... controller/id ... is segment(2)
<1 - needs help> is ther e a standard for knowing how the controlerl was called
<1 - needs help> *bah fingers*
* #chemistry ##chemistry :Forwarding to another channel
<2 - helping> you could always use rsegment()
<1 - needs help> *looks that up*
<2 - helping> that's one way of being *real* sure
<2 - helping> the segment always refers to the segment, as it is in the URI
* Antivanity has quit (". . . . . http://www.yumsearch.com . . . . .")
<2 - helping> the rsegment refers to the routed segment, eg: '(foo/[0-9]+)' = 'foo/bar/$1'
<1 - needs help> hmmmmmmmmm
<2 - helping> the segment(2) would be the number
<2 - helping> and the rsegment(2) would be 'bar'
<2 - helping> if there is no route, segment === rsegment
<1 - needs help> so it essentially puts /index/ back into the url for means of coutning uri segments?
<2 - helping> in your example, yah
<1 - needs help> cool beans
<1 - needs help> and if you access foo/bar/id directly ... is rsegment(3) ... id
<1 - needs help> suppose i can check heh
<2 - helping> yes
* Antivanity ([email protected]) has joined #codeigniter
<1 - needs help> hmmm, in foo/id ... id is rsegment(4) ... but in ... foo/index/id ... id is rsegment(3)
<1 - needs help> even wierder .... in /foo/id .... rsegment(1)==foo ... rsegment(2)==index ... rsegment(3)==foo ... rsegment(4)==id
* Char80|w is now known as Char80
<1 - needs help> thats whack!
<2 - helping> interesting
<2 - helping> CI got bugs!
<2 - helping> Wink
<1 - needs help> hahah
<2 - helping> i had to rewrite Router completely when i did Kohana
<2 - helping> like... 100% re-done
<1 - needs help> so its foo/index/foo/id ... for some reason
<2 - helping> it was horrible
<2 - helping> oh, well look at the route
<2 - helping> => 'foo/index/$1
* champs|work has quit ("manamana.")
<2 - helping> and the first part: '(foo/[0-9]+)'
<2 - helping> is capturing the whole thing
<2 - helping> so, if you want just the ID transposed, you need: 'foo/([0-9]+)' => 'foo/index/$1'
<1 - needs help> without the (
<1 - needs help> ?
<2 - helping> no
<1 - needs help> i have $route["(org/[0-9]+)"] = "org/index/$1"; already
<2 - helping> in regex, (this will be captured)
<2 - helping> anything inside of parens is assigned to the "callback"
<1 - needs help> oh
<1 - needs help> so remove them then
<2 - helping> so, (one)/two/(three), $1 = one, $2 = three
<1 - needs help> got it
<1 - needs help> so i really want ... $route["org/([0-9]+)"]
<2 - helping> yes
<1 - needs help> never understood that, thanks Smile
<2 - helping> regex is a programming language all in itself
<2 - helping> Big Grin
<1 - needs help> yes, yes it is
<1 - needs help> i have used it for very simple things
<1 - needs help> but not much else
<2 - helping> <1 - needs help>: there's always fun like this: http://kohanaphp.com/trac/browser/trunk/...8.php#L678
<1 - needs help> bahahahahahah
<1 - needs help> i'll get right on that! Smile
<2 - helping> lol
<1 - needs help> *jumps up and down: routes work!*


Messages In This Thread
Routes: how to get mycontroller/id function same as mycontroller/action/id - by El Forum - 10-19-2007, 05:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB