Khirad Zahra
Khirad Zahra

Reputation: 893

Routes conflicts in codeigniter 3

My defined routes

$route['search/results/(:any)'] = 'search/results/$1';
$route['search/(:any)'] = 'search/index/$1';

Whenever i try to access the first route it always redirects to index method? I have tried replacing the position of index routes as well. Here is how i am calling results route from the URL

http://localhost:8888/revam/search/results/?type=books

Any help will be highly appreciated.

Upvotes: 0

Views: 68

Answers (2)

Bruno Assis
Bruno Assis

Reputation: 1006

There is also a simpler way to solve this, since you are not calling the url by using url segments after the /search/results/ you could build your routes like this:

$route['search/results'] = 'search/results/$1';
$route['search/(:any)'] = 'search/index/$1';

Upvotes: 1

Asim Shahzad
Asim Shahzad

Reputation: 1609

Here after question mark type=books is parsing as query parameters not as route,that's its leading to index method.

One way to handle this is to update your route with something like this.

$route['search/results?(:any)'] = 'search/results/$1';
$route['search/(:any)'] = 'search/index/$1';

Hope this helps.

Upvotes: 1

Related Questions