[英]Clean urls cannot get function id in CodeIgniter
I am using CodeIgniter in my project and I need to clean the url. 我在项目中使用CodeIgniter,我需要清理URL。 I use this htaccess:
我用这个htaccess的:
RewriteEngine On
RewriteCond $0 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^.*$ index.php [L]
The url redirect is working fine. 网址重定向工作正常。 If I use
localhost/example/controll/
this works fine, if I have an controll
as controller, but if I need to pass a value to the controller like localhost/example/controll/how-to-design/
it says 404 not found. 如果我使用
localhost/example/controll/
这很好,如果我有一个controll
作为控制器,但是如果我需要将一个值传递给localhost/example/controll/how-to-design/
这样的localhost/example/controll/how-to-design/
则表示找不到404 。 Do I need to get the how-to design in controll
class and process it? 我是否需要在
controll
类中获得操作方法设计并进行处理?
the URL localhost/example/controll/how-to-design
translates to a controller called controll
and a method called how-to-design
URL
localhost/example/controll/how-to-design
转换为称为controll
和称为how-to-design
CI will be looking for a method called how-to-design
, which presumably doesn't exist. CI将寻找一种名为
how-to-design
,该方法可能不存在。
If you want to pass that parameter to controll
the URL needs to be: 如果要传递该参数进行
controll
则URL必须为:
controll/index/how-to-design
function index($param)
{
echo $param; // echoes how-to-design
}
you can probably fix this with routing or by using index
in your URI. 您可能可以通过路由或在URI中使用
index
来解决此问题。
You can't by default in CodeIgniter pass parameters to the controller index function - in your example CI would be looking for a method called 'how-to-design' (which in itself is impossible, as dashes are not permitted in PHP function naming conventions). 默认情况下,您无法在CodeIgniter中将参数传递给控制器索引函数-在您的示例CI中,我们正在寻找一种名为“如何设计”的方法(这本身是不可能的,因为PHP函数命名中不允许使用破折号)约定)。
You can use the special _remap method in your controller to manually handle the routing - http://codeigniter.com/user_guide/general/controllers.html#remapping - or you could set up some manual routes in config/routes.php 您可以使用特殊的方法_remap在控制器手动处理路由- http://codeigniter.com/user_guide/general/controllers.html#remapping -或者你可以设置在配置/ routes.php文件进行一些手动路线
如果要实现此功能,请编写一个新函数并在routes.php中为其定义自定义路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.