Organizational Research By

Surprising Reserch Topic

how to create codeigniter route that doesnt override the other controller route


how to create codeigniter route that doesnt override the other controller route  using -'codeigniter,routes'

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:


if people goes to url: example.com/signup, I want use default route to "Signup" Controller
if people goes to url: example.com/bobby.ariffin, I want to reroute this to "User" Controller because the url not handled by any Controller in my apps.


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.
    

asked Sep 15, 2015 by OttoVERXiidk
0 votes
3 views



Related Hot Questions

2 Answers

0 votes

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";
answered Sep 15, 2015 by KelSteen
0 votes

You're going to have to explicitly define all of those routes. Otherwise you will always end up at the "user_controller".

$route['signup'] = "signup";
$route['(:any)'] = "user/display/$1";

or something similar. They are ran in order, so what ever is defined first, is going to happen first. So if you catch (:any), you're going to send ANYTHING to that controller.

Also keep in mind that you can use regular expressions, so if you know there is always going to be a '.' in there, you could test for that.

answered Sep 15, 2015 by EliCordova

...