Nyxynyx
Nyxynyx

Reputation: 63727

More than 1 controller function name in URI

Using Codeigniter, I have a controller function name search that takes in parameters state and city in the URI segments http://www.mysite.com/functionA/MA/Boston/0 where 0 is used by the pagination class. The controller function declaration will thus look like:

function search(state, city) {
    ...
}

Problem: For SEO purposes and to get pretty URLs, I want http://www.mysite.com/search/MA/Boston/view/12345 to show a particular page for product id 12345. In this case, View is our second controller function defined by

function view(pid) {
    ...
}

And the first controller function search does not do anything in this case, its there in the URL just to make the URL pretty etc. So view is the only working controller function.

How can I achieve this?

Upvotes: 0

Views: 104

Answers (1)

Farzher
Farzher

Reputation: 14593

URI Routing

http://ellislab.com/codeigniter/user_guide/general/routing.html

Something like this mayhaps?

//goes in application/config/routes.php
$route['search/(:any)/(:any)/view/(:num)'] = "view/$3";

This gets any URI that looks like search/something/whatever/view/325 and reroutes it to view/325

Upvotes: 2

Related Questions