CodeIgniter:将参数传递给控制器​​时找不到页面?

发布于 2024-08-31 04:25:02 字数 631 浏览 1 评论 0原文

我试图将参数传递给 codeigniter 中的控件,但收到 404 page not find 错误,我不明白,我按照指南所述操作: http://codeigniter.com/user_guide/general/controllers.html#passinguri

当我删除索引函数中的参数并且只是访问控制器一切正常,但我无法向它传递值...

这是我尝试发送参数的方式的代码:

http://mysite/123

<?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:

http://mysite/123

<?php
class Main extends Controller {

    function index($username) {

        echo $username;

    }

}
?>

How can I get more info regarding this error from codeigniter?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不美如何 2024-09-07 04:25:02

使用该 URL,CodeIgniter 无法理解您是否要将 123 传递给 index 方法,或者是否使用以下命令请求 123 方法无参数。如果需要向默认方法传递一些参数,则必须显式命名该方法。

http://mysite/index/123

With that URL, CodeIgniter can't understand if you want to pass 123 to the index method or if you're requesting the 123 method with no parameters. You have to explicitly name the default method if you need to pass it some parameters.

http://mysite/index/123
不交电费瞎发啥光 2024-09-07 04:25:02

选项 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文