如何通过 Codeigniter 框架使用表单进行分页?

发布于 2024-12-22 10:52:41 字数 277 浏览 2 评论 0原文

我正在使用 Codeigniter 框架,并且正在创建注册表单。注册过程通过多个步骤完成 - 我为此创建了不同的视图。

我遇到的问题是让控制器读取我已继续执行新步骤。我尝试通过将表单发布到 index.php/controller/2 来解决此问题,但当我到达该页面时,我收到 404 错误,指出

该页面不存在。

我已经加载了 URI 帮助程序,所以我不太明白问题出在哪里。

非常感谢所有帮助

I'm using the Codeigniter framework and am in the process of creating a registration form. The registration process is completed in multiple steps- for which I've created different views.

What I have a problem with is making the controller read that I've continued to a new step. I tried solving this by posting the form to index.php/controller/2 but as I reach the page I get a 404 error stating

The page doesn't exist.

I've loaded the URI helper so I don't quite understand where the problem lies.

All help is very much appreciated

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

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

发布评论

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

评论(1

酷炫老祖宗 2024-12-29 10:52:41

通过将表单提交到 index.php/controller/2 您实际上是在说

  • Load /application/controllers/Controller.php
  • Instantiate class Controller
  • Run Controller::2()

我怀疑您没有一个名为 2 的方法,并且您希望将两个作为参数传递给处理步骤 1 的方法。这可能是 /controller/register 或类似的。

您需要将表单提交到 index.php/controller/method/2 并在 method 内使用 $this->uri 检查您正在执行哪个步骤->segment(2)

理想情况下,为每个步骤创建不同的方法,因为它可以更好地分离逻辑。例如,

class Registration {
    function step_1() {}
    function step_2() {}
}

这将允许您调用 index.php/registration/step_1/index.php/registration/step_2/

您可能还希望使用 Session 类来设置指示哪些阶段已完成的变量,以防止人们通过键入 URL 跳到其他阶段。

By submitting the form to index.php/controller/2 you're effectively saying

  • Load /application/controllers/Controller.php
  • Instantiate class Controller
  • Run Controller::2()

I suspect you don't have a method named 2, and you want to pass two as an argument to a method which handles step 1. Which might be /controller/register or similar.

You need to submit your form to index.php/controller/method/2 and inside method check which step you're on using $this->uri->segment(2)

Ideally, create a different method for each step as it'll better separate the logic. For example

class Registration {
    function step_1() {}
    function step_2() {}
}

Which will allow you to call index.php/registration/step_1/ and index.php/registration/step_2/ for example.

You may also wish to use the Session class to set variables indicating which stages are complete to prevent people skipping to other stages by typing in the URL.

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