Codeigniter Routing automatically

177 views Asked by At

I want to route multiple controllers.

I do have the following construct:

Controllers: app_cart , cart , app_categories , categories , etc

I want to route to the app_cart controller if the url is like this:

url.com/app/cart

and to cart when url is like this:

url.com/cart (thats what codeigniter does on his own!)

Any solutions? I dont want to route every single funtion and param! :/

EDIT:

I found a solution:

$route['app/(:any)'] = 'app_$1';

Hope this will help somebody! ;)

2

There are 2 answers

2
Asik On

Apply this in your application/config/routes.php

For Controller: app_cart

$route['app/cart'] = "app_cart"; 

For Controller: app_categories

$route['app/categories'] = "app_categories"; 

Note: The above settings point your index function/method for your controllers because still you are not mention function/method name in the url

If you want to point specific function/method for your controllers, then you should mention the name in URL. Below is a sample configuration

For Controller: app_cart/view

$route['app/cart/view'] = "app_cart/view"; 

For Controller: app_categories/view

$route['app/categories/view'] = "app_categories/view"; 

Note: view is a function/method name for your controllers

0
fr3ddyf On

I found a solution:

$route['app/(:any)'] = 'app_$1';