user2177396
user2177396

Reputation: 31

codeigniter pass the parameter before the method in the url?

im trying to pass parameters into a controler on CodeIgniter but i want the url to be like that :

mywebsite/profile/{user_id}/about

and not like this :

mywebsite/profile/about/{user_id}

so it possible please ? and how can we do it ?

Upvotes: 3

Views: 190

Answers (1)

Patrick Manser
Patrick Manser

Reputation: 1183

This worked for me, I just tested it:

In the routes.php create a new route, that looks like the following:

$route['profile/(:any)/about'] = 'profile/about/$1';

That will rewrite the URL from e.g. "yoursite.com/profile/about/23" to "yoursite.com/profile/23/about". I assume, that "profile" is your controller and "about" is the function.

Hope, this helps! Didn't test it with an ID that comes from a database, though.

Upvotes: 5

Related Questions