skip to Main Content

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

www.abc.com/mumbai-hotels

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


  1. suppose url is like following : http://www.paintes.com/painters-in-chennai
    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 http://www.paintes.com/painters-in-mumbai , then output will be mumbai

    as per your request, URL is liek following : http://www.paintes.com/mumbai-painters
    then you can write like following

        $route['(:any)-painters'] ='index/paintersIn/$1';
    
    Login or Signup to reply.
  2. You could do something like this :

    $route['(:any)-(:any)'] = 'serviceController/info';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search