Reputation: 2311
I have in my routes.php
:
$route['ctrller1/method1/video/(:num)'] = 'ctrller2/method2/$1';
I also have a controller that is named ctrller1
that has a method:
function method1 ($str = NULL) {
// do something
}
The problem is I have to use controller2 coz I can't or shouldn't edit controller1. What I want is seemingly simple but, apparently, CI doesn't want to work with me.
When the url:
domain.com/ctrller1/method1/edit
is invoked, I want the method inside ctrller1
to be called, if domain.com/ctrller1/method1/videos/1
is invoked I want the method in ctrller2
called.
It all seems correct to me but it won't work. So, I must be missing something. I've tried adding this to the routing:
$route['ctrller1/method1/(edit)'] = 'ctrller1/method1/($1)';
But it's a no go. Anyone see anything wrong here?
Upvotes: 2
Views: 1848
Reputation: 20475
At any time when you work with routes, just like permissions (firewall, etc;) order is important. Typically you want to organize your routes in this order:
To clarify, that means your order for routes should be like this:
$route['ctrller1/method1/videos/view/(:num)'] = 'ctrller2/method3/$1';
$route['ctrller1/method1/videos/(:num)'] = 'ctrller2/method2/$1';
$route['ctrller1/(:num)'] = 'ctrller2/method1/$1';
When the URL is called, the route table goes through and finds the FIRST closest match, ELSE it traverses to the next route.
In this case what you want is something like this:
domain.com/ctrller1/method1/videos/1
domain.com/ctrller1/method1/edit
Reasoning for that is, the video's route is more specific, and also is a SPECIAL CASE, as you route it to another controller behind the scenes.
Here is what your routes should look like then (not tested, but should be it):
$route['ctrller1/method1/videos/(:num)'] = 'ctrller2/method2/$1';
$route['ctrller1/method1/edit'] = 'ctrller1/method1';
As a side, note, I am curious why you format it ctrller1/method1/videos/
and not something like ctrller1/videos/view/12355
or ctrller1/videos/edit/12355
, the method1
seems confusing. But again I don't have all the details here.
Hope that works for you, if not comment, and I will revisit your question if you clarify it a little more.
Upvotes: 1
Reputation: 10996
Well you have video
on one place and videos
on another?
Either change to
$route['ctrller1/method1/videos/(:num)'] = 'ctrller2/method2/$1';
or try url: domain.com/ctrller1/method1/video/1
Upvotes: 0