[英]CodeIgniter - how to remove class name in url route
I have http://localhost/CIrbbps/index.php/class_name/method_name . 我有http://localhost/CIrbbps/index.php/class_name/method_name 。 how to remove class name?, so i can get just http://localhost/CIrbbps/index.php/method_name .
如何删除类名?,所以我只能得到http://localhost/CIrbbps/index.php/method_name 。 thank you
谢谢
In order to map www.domain.com/services
to pages/services
you would go like: 为了将
www.domain.com/services
映射到pages/services
您会喜欢:
$route['services'] = 'pages/services'
If you want to map www.domain.com/whatever
to pages/whatever
and whatever has a few variants and you have a few controllers, then you would do : 如果你想将
www.domain.com/whatever
映射到pages/whatever
以及有什么变体和你有几个控制器,那么你会做:
// create rules above this one for all the controllers. //为所有控制器创建高于此值的规则。
$route['(:any)'] = 'pages/$1'
That is, you need to create rules for all your controllers/actions
and the last one should be a catch-all rule, as pointed above. 也就是说,您需要为所有
controllers/actions
创建规则,最后一个应该是一个包罗万象的规则,如上所述。
If you have too many controllers and you want to tackle this particular route, the in your routes.php
file it is safe to: 如果您有太多的控制器并且想要处理这个特定的路由,那么在
routes.php
文件中,它是安全的:
$path = trim($_SERVER['PATH_INFO'], '/');
$toMap = array('services', 'something');
foreach ($toMap as $map) {
if (strpos($path, $map) === 0) {
$route[$map] = 'pages/'.$map;
}
}
Note, instead of $_SERVER['PATH_INFO']
you might want to try $_SERVER['ORIG_PATH_INFO']
or whatever component that gives you the full url path. 注意,您可能想要尝试
$_SERVER['ORIG_PATH_INFO']
或任何为您提供完整网址路径的组件,而不是$_SERVER['PATH_INFO']
。 Also, the above is not tested, it's just an example to get you started. 此外,上面没有经过测试,这只是一个让你入门的例子。
CodeIgniter Routes - remove a classname from URL for one class only CodeIgniter路由 - 仅从一个类的URL中删除一个类名
试试这个:
$route['(:any)'] = "account/$1";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.