Codeignitor URL Conflicts

Hello there i am working on web app built with codeignitor where i am suppose to show the services available withing cities.

For this i am trying to create url like

where mumbai is city name and hotels is service to be search within city

Now uptill i have following code in my routes.php file

$route['(about-us)'] = 'websiteController/aboutus';   
$route['(:any)'] = 'serviceController/info'; 

The first line from routes.php suppose to redirect to aboutus action of webiste controller. And second line is suppose to redirect to info action inside the serviceController.

But unfortunately this is not happening, but it creating conflict and in both case it is still
redirecting to service controller.

Does any one have idea what mistake i am making here, and put me on proper track

2 answers

  • answered 2019-12-06 07:32 Mac Rathod

    suppose url is like following : then route can be like following

        $route['painters-in-(:any)'] ='index/paintersIn/$1';

    in index.php controller, i'll be able to receive chennai like following

        function paintesIn($city_name)
            echo $city_name //OUTPUT WILL BE "chennai"

    if url is like , then output will be mumbai

    as per your request, URL is liek following : then you can write like following

        $route['(:any)-painters'] ='index/paintersIn/$1';

  • answered 2019-12-06 08:24 Krishna Savani

    You could do something like this :

    $route['(:any)-(:any)'] = 'serviceController/info';