Welcome Guest, Not a member yet? Register   Sign In
uri routing to index()
#1

[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
#2

[eluser]Hermawan Haryanto[/eluser]
Look at the /config/routes.php (ant the user guide here: http://ellislab.com/codeigniter/user-gui...uting.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
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB