CodeIgniter:将参数传递给控制器时找不到页面?
我试图将参数传递给 codeigniter 中的控件,但收到 404 page not find 错误,我不明白,我按照指南所述操作: http://codeigniter.com/user_guide/general/controllers.html#passinguri
当我删除索引函数中的参数并且只是访问控制器一切正常,但我无法向它传递值...
这是我尝试发送参数的方式的代码:
<?php
class Main extends Controller {
function index($username) {
echo $username;
}
}
?>
如何从 codeigniter 获取有关此错误的更多信息?
谢谢。
I'm trying to pass parameters to a control in codeigniter, but I'm getting 404 page not found error, I don't get it, I did what the guide says: http://codeigniter.com/user_guide/general/controllers.html#passinguri
When I remove the params in the index function and just access the controller everything works fine, but I can't pass a value to it...
Here is the code the way I'm trying to send a param:
<?php
class Main extends Controller {
function index($username) {
echo $username;
}
}
?>
How can I get more info regarding this error from codeigniter?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用该 URL,CodeIgniter 无法理解您是否要将
123
传递给index
方法,或者是否使用以下命令请求123
方法无参数。如果需要向默认方法传递一些参数,则必须显式命名该方法。With that URL, CodeIgniter can't understand if you want to pass
123
to theindex
method or if you're requesting the123
method with no parameters. You have to explicitly name the default method if you need to pass it some parameters.选项 1 - 在控制器中重新映射函数调用
如果您的控制器包含名为 _remap() 的函数,则无论您的 URI 包含什么内容,它都将始终被调用。它会覆盖 URI 确定调用哪个函数的正常行为,从而允许您定义自己的函数路由规则。
http://codeigniter.com/user_guide/general/controllers.html#remapping
选项 2 - 使用自定义路线。
http://codeigniter.com/user_guide/general/routing.html
Option 1 - Rempap the function call in your controller
If your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called, allowing you to define your own function routing rules.
http://codeigniter.com/user_guide/general/controllers.html#remapping
Option 2 - Use a custom route.
http://codeigniter.com/user_guide/general/routing.html