5

I developed a project in php codeigniter. The project is almost complete but now my manager wants me to completely remove or hide the controller names in the URL. My current URL looks like this:

http://www.sitename.com/Controller_Name/function_name

and my manager wants it to look like this:

http://www.sitename.com/function_name

Note that I have more than 10 controllers in my project and many many functions. I want a method that applies to all. HELP PLEASE.

Ajmal Razeel
  • 1,663
  • 7
  • 27
  • 51

2 Answers2

7

You can do this using $route.

If you have only one Controller and in that controller you all the functions you can write something like this:

$route['(:any)'] = "Controller_Name/$1";

If you have many Controllers you need to specify for each function to what controller to point. Like this:

$route['function1'] = "Controller_Name1/function1";
$route['function2'] = "Controller_Name1/function2";
$route['function3'] = "Controller_Name3/function3";

And you can't have duplicates in $route

This $route array should be located here: application/config/routes.php.

You can check more about routes on the CI documentation here: https://www.codeigniter.com/userguide3/general/routing.html

Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39
1

You have to specify your controller and method name in routes file like below

$route['function_name'] = 'controller_name/function_name';

You have to write this for each function in controller.By doing you get two advantages

1) Controller name will be hidden in your url 2) you can call some method by its name only.No need to use controller name every time.

Shaunak
  • 78
  • 10