CodeIgniter:尾部斜杠

发布于 2024-10-02 14:03:23 字数 571 浏览 0 评论 0原文

在我的 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 技术交流群。

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

发布评论

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

评论(2

动次打次papapa 2024-10-09 14:03:23

在操作中使用绝对 URL

action="/myapp/index.php/frontend/submit/"

Use an absolute URL in the action

action="/myapp/index.php/frontend/submit/"
三生殊途 2024-10-09 14:03:23

你在使用 CI 的表单助手吗?

//autoload/controller:
$this->load->helper('form');
// in your view:
<?php echo form_open('login/submit'); ?>

当你有一个“前端”时 - 如何设置 - 只是控制器目录中的一个文件夹?

URL 不应对结果产生任何影响。

您可能需要

但我不这么认为
IE

controllers/
   |-frontend
       |-front_end_controller.php

are you using CI's form helper?

//autoload/controller:
$this->load->helper('form');
// in your view:
<?php echo form_open('login/submit'); ?>

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

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