如何通过 Codeigniter 框架使用表单进行分页?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将表单提交到
index.php/controller/2
您实际上是在说我怀疑您没有一个名为 2 的方法,并且您希望将两个作为参数传递给处理步骤 1 的方法。这可能是
/controller/register
或类似的。您需要将表单提交到
index.php/controller/method/2
并在method
内使用$this->uri 检查您正在执行哪个步骤->segment(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 sayingI 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 insidemethod
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
Which will allow you to call
index.php/registration/step_1/
andindex.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.