I've got a lot controller in my Codeigniter apps, ex: Signup, Profile, Main, etc..
Now I want to build "User" controller.
what I want:
I had create this in my config/routes.php:
$route['(:any)'] = "user";
but it's override all the route in my apps to "User" Controller.
Is there any simple route for Codeigniter that doesn't override the other controller routes?
Update---
I've got simple regex for this problem, from: Daniel Errante's Blog
$route['^(?!ezstore|ezsell|login).*'] = “home/$0″;
where ezstore, ezsell, and login are the name of controller in Your Apps.
URI Routing associates a URI with a controller's method. CodeIgniter has two kinds of routing. One is Defined Route Routing, and the other is Auto Routing. With Defined Route Routing, you can define routes manually.
All you need to do is to add the verb as an array key to your route. Example: $route['products']['put'] = 'product/insert'; In the above example, a PUT request to URI “products” would call the Product::insert() controller method.
URLs in CodeIgniter are designed to be short and search engine friendly. It should make more sense to the visitors. A user should get an idea about the page content through its URL.
Routing rules are defined in the app/Config/Routes. In it you'll see that it creates an instance of the RouteCollection class ( $routes ) that permits you to specify your own routing criteria. Routes can be specified using placeholders or Regular Expressions.
You can also use a foreach statement for this. That way you can keep your controllers in a nice neat list.
$controller_list = array('auth','dashboard','login','50_other_controllers');
foreach($controller_list as $controller_name)
{
$route[$controller_item] = $controller_name;
}
$route['(:any)'] = "user/display/$1";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With