Reputation: 4090
Ok, so maybe that title is a bit confusing. What I'd like to do is trap any info, if any after the first URI segement if that segment is something specific and forward that on to another controller. Here's my routes file:
$route['default_controller'] = "main";
$route['404_override'] = '';
$route['testroute'] = "main";
So, what this does right now is, if I got to mydomain.com/testroute it shows me the default page, which it should. However, what I'd like is if I go to mydomain.com/testroute/testmethod/ where testmethod is a method in the main controller I'd like it to forward that as well. So basically I'd like it to route to the main controller regardless of if there are more segments after the testroute, but if there are they should get passed as method calls of the main controller.
Upvotes: 2
Views: 2739
Reputation: 3396
Simply catch the parameter given and pass it to the controller e.g. like this:
$route['testroute/(:any)'] = "main/$1";
(:any)
actually catches any type of string. There are other selectors, as well. More on this topic can be found here.
Edit (answer to your comment):
If you want a general route to the index() method of your main controller, just add both routes:
$route['testroute'] = "main";
$route['testroute/(:any)'] = "main/$1";
Upvotes: 3
Reputation: 18295
Uh, what? That's how CodeIgniter's controllers work already. Show us some code? What isn't working about it?
Have you configured URL rewriting in your .htaccess file so you don't need the /index.php/testroute
in the URL?
Open .htaccess, and try this code if you haven't already rewritten this:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
If you haven't configured rewriting then it won't work without that^, but you can access like mydomain.com/path/to/ci/index.php/testroute/testmethod
Upvotes: 0