CodeIgniter:尾部斜杠
在我的 CI 应用程序中,我有以下控制器:
http://localhost/myapp/index.php/frontend/login/
在此控制器(登录控制器)中,我有一个名为 submit()
的方法。该控制器的关联视图文件具有带有 action='submit/'
的表单。这个想法是,当表单提交时,它会转到 http://localhost/myapp/index.php/frontend/login/
——只要 URL 结尾有斜杠,它就会这样做。
但是,如果 URL 是这样的(没有尾部斜杠):
http://localhost/myapp/index.php/frontend/login
并且我提交了表单,我会被重定向到以下内容:
http://localhost/myapp/index.php/frontend/submit/
这会导致 404,因为我没有 submit
控制器。
In my CI app, I have the following controller:
http://localhost/myapp/index.php/frontend/login/
In this controller (the login controller), I have a method called submit()
. The association view file for this controller has a form with action='submit/'
. The idea is when the form submits, it goes to http://localhost/myapp/index.php/frontend/login/
-- and it does as long as the URL has a trailing slash.
However, if the URL is like this (no trailing slash):
http://localhost/myapp/index.php/frontend/login
and I submit the form, I am redirected to the following instead:
http://localhost/myapp/index.php/frontend/submit/
This results in a 404 since I don't have a submit
controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在操作中使用绝对 URL
Use an absolute URL in the action
你在使用 CI 的表单助手吗?
当你有一个“前端”时 - 如何设置 - 只是控制器目录中的一个文件夹?
URL 不应对结果产生任何影响。
您可能需要
但我不这么认为
IE
are you using CI's form helper?
and when you have a "frontend" - how is that set up - just a folder within the controller directory?
the URL shouldn't have any effect on the outcome.
you may need
<?php echo form_open('frontend/login/submit'); ?>
but i don't think so
ie