tmartin314
tmartin314

Reputation: 4171

Automating routes with Codeigniter

I'm integrating CI into another script as a module, and I need to configure and setup routes to work normally but from inside this parent scripts mod rewrites and so on.

Basically to start the Parent Script routes all URL's with m/MODULE_NAME to a module folder. Inside this module folder is where I have CI taking over and handling requests sent to it.

When I view all the segments of a request to: http://www.example.com/folder/m/memberships

CI prints the segments out like this:

array( [0] => 'folder', [1] => 'm', [2] => 'memberships' )

I'm trying to figure out how I can change the configuration settings so that Routing is done automatically after /m/memberships.

Right now I am basically setting each route up individually:

// Main config routes
$route['(:any)/m/memberships'] = 'home';
$route['(:any)/m/memberships/admin'] = 'admin/dashboard';
$route['(:any)/m/memberships/admin/config'] = 'admin/config';

I tried setting the base url to http://www.domain.com/m/memberships, but then even the routes listed here weren't being added to segments and I couldn't point them to the proper controllers.

Anyone have any suggestions? I'm fairly new to CI.

EDIT: These are some configs I have setup that might help:

$config['base_url']   = 'http://www.domain.com/folder/';
$config['index_page']    = '';
$config['uri_protocol']  = 'AUTO';

Upvotes: 1

Views: 179

Answers (1)

Jakub Riedl
Jakub Riedl

Reputation: 1086

There are two ways how to do that

1) is set $config['base_url'] = 'http://www.domain.com/folder/m/memberships'; and clear routes

2) set route $route['m/memberships/(:any)/(:any)'] = '$1/$2';

the first one is much cleaner

Upvotes: 1

Related Questions