CodeIgniter - how to remove class name in url
I have http: //localhost/CIrbbps/index.php/class_name/method_name . how to remove the class name? so I can only get http: //localhost/CIrbbps/index.php/method_name . thank
source to share
To map www.domain.com/services
to pages/services
, you would like:
$route['services'] = 'pages/services'
If you want to map www.domain.com/whatever
to pages/whatever
and anything that has multiple choices and you have multiple controllers, you should:
// create rules above this for all controllers.
$route['(:any)'] = 'pages/$1'
That is, you need to create rules for all of yours controllers/actions
, and the last one should be a catch-all rule as above.
If you have too many controllers and want to decide this particular route, in your file routes.php
it is safe to:
$path = trim($_SERVER['PATH_INFO'], '/');
$toMap = array('services', 'something');
foreach ($toMap as $map) {
if (strpos($path, $map) === 0) {
$route[$map] = 'pages/'.$map;
}
}
Note. Instead, $_SERVER['PATH_INFO']
you can try $_SERVER['ORIG_PATH_INFO']
or any other component that will give you the full url. Also, the above is untested, this is just an example to get you started.
CodeIgniter Routes - Remove class name from url for only one class
source to share