0

I have two different controllers which I want to route to the same URL.

For example,

$route['dashboard/(:any)'] = 'admin/crud/$1';
$route['dashboard/(:any)'] = 'admin/dashboard/$1';

But this is causing 404 errors.

I guess there is some issue with the :any wildcard.

Is there an alternative to use?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
murtazamzk
  • 191
  • 1
  • 2
  • 7

1 Answers1

1

CodeIgniter doesn't map controllers to URLs, it maps URLs to controllers. See URI Routing.

You are trying to map two same exact URLs to go to different places. This doesn't make sense.

Also, since $route is just an associative array, you are overwriting the value instead of adding an additional route.

$route['dashboard/(:any)'] = 'admin/crud/$1';
$route['dashboard/(:any)'] = 'admin/dashboard/$1'; //Immediately over writes the previous value

So, it looks like you just have a problem with the second route:

$route['dashboard/(:any)'] = 'admin/dashboard/$1';

Since, admin is the folder, double check that the value being passed in by the route actually is a method in your dashboard controller class.

Also, check out this question and accepted answer: routing controllers in sub folders - codeigniter I think it provides an example of what you are attempting to do.

Community
  • 1
  • 1
dmullings
  • 7,070
  • 5
  • 28
  • 28
  • admin is a folder and dashboard is the contoller , I am getting 404 for dashboard/add/ – murtazamzk Dec 07 '14 at 09:28
  • Ok, didn't know that. If `dashboard` is the controller, then I think `(:any)` is being passed as the function in that controller to run. So based on the error, it looks like whatever function name is being passed it isn't being found in the controller. – dmullings Dec 07 '14 at 14:46