CodeIgniter Forums
uri routing to index() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: uri routing to index() (/showthread.php?tid=8163)



uri routing to index() - El Forum - 05-07-2008

[eluser]-sek[/eluser]
The CI documents give the routing as

class/function/param/param/ etc.

Working on a new class, I noticed that I was getting a 404 Error with

/friends/pending/

friends is the controller class and pending is the parameter.

After puzzling with this a bit, I discovered CI apparently does not honor the routing convention for the index() function.

I didn't want a url like

friends/friends/pending
or
friends/browse/pending

Just

friends/

for the default listing and

friends/pending

for the pending listing.

I know that I can put the code into another function, browse() or friends() and specify a routing that does not mention the function name, but it seems strange that I can't pass a parameter to index().

Any ideas?

Steve


uri routing to index() - El Forum - 05-08-2008

[eluser]Hermawan Haryanto[/eluser]
Look at the /config/routes.php (ant the user guide here: http://ellislab.com/codeigniter/user-guide/general/routing.html)
I'm sure you can make something like this:
Code:
$route['friends/:any'] = 'friends';

Then on the friends/index controller, you could grab that "pending" as
Code:
$this->uri->segment(2);

Good luck,
Hermawan Haryanto


uri routing to index() - El Forum - 05-08-2008

[eluser]-sek[/eluser]
Appreciate the help. My current solution is to create a browse function

Code:
function browse() {}

and get the parameter from

Code:
$this->uri->segment(3);

with

Code:
$route['friends'] = "friends/browse";

in routes to hide the existence of the browse function. I still do not know if this is compatible with the CI pagination library.

I wonder which method would fail more gracefully if someone forgot to specify the route? Depending on routing bugs me.