1

Using CI how can I route to specific contoller with any method name. I have two controller : init and cms. Then in config.routes.php :

 $default_controller = "init";  //default controller
 $controller_exceptions = array('admin','forums');

 $route['default_controller'] = $default_controller;
 $route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
 $route['404_override'] = '';

 $route['backend'] = 'cms';
 $route['backend/(:any)'] = "cms/product";  

When backend/product is typed I want it to route to backend/product. Again when backend/login is typed I want it to route to backend/login. That means what I need is $route['backend/anyMethodNameAfterbackend'] = "cms/anyMethodNameAfterbackend";

1 Answer 1

1

Instead of $route['backend/(:any)'] = "cms/product"; use $route['cms/(:any)'] = "cms/$1"; The result would be :

$route['backend'] = 'cms';
$route['backend/(:any)'] = "cms/$1";
Sign up to request clarification or add additional context in comments.

8 Comments

Its not working. I did the same. Real path for login to my site is. localhost/c2c/index.php/cms. This has login form with action form_open('cms/login'). I typed localhost/c2c/backend then pages opens but when trying to login throws an 404 error.
Well then, try form_open(base_url().'cms/login') or form_open('/cms/login').
Still not working. When trying to login. Press login then my url becomes localhost/c2c/cms/login not localhost/c2c/backend/login
That would be the same. You have another problem, one that is not related to routing. If you change '/cms/login', to '/backend/login', the uri will be correct, but the page will display the same error. What does your cms controller look like?
cms controller is simple that contains functions. I remember that i am removing the contoller name to be written in url by configuring htaccess. Does it make problem
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.