Codeigniter中的表单操作被添加到现有URL [英] Form Actions in Codeigniter gets added to the existing URL

查看:60
本文介绍了Codeigniter中的表单操作被添加到现有URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Codeigniter的新手,我面临一个小问题。我有一个名为 test的控制器,想在该控制器中调用 edit_details操作。这是我正在开发的测试应用程序。我想更新用户信息,并通过以下URL发送用户ID(URL段): http://localhost/codeigniter/index.php/test/edit/12。编辑操作会使用可在其中输入用户详细信息的表单加载视图。这是使用视图中的锚点完成的(每个记录旁边的编辑链接)。锚点: test / edit / $ row-> id。到目前为止,一切都工作正常。

I am new to codeigniter and i am facing a small issue. I have a controller named "test" and would like to call the "edit_details" action within that controller. This is a test application i am developing. I would like to update a user's information and i am sending the user id via(URL segments) the URL: "http://localhost/codeigniter/index.php/test/edit/12" as an example. The edit action loads the view with a form where the user's details could be entered. This is done using an anchor from the view(an edit link next to each record). Anchor: "test/edit/$row->id". Everything so far works great.

问题是,当我使用操作 test / update_details提交表单时,URL变为 http:// localhost / codeigniter /index.php/test/edit/test/update_details'。 edit_details操作加载一个模型,然后该模型执行数据库工作。 ID是使用视图中的隐藏字段发送的。

The problem is when i submit the form with the action 'test/update_details', the url then becomes "http://localhost/codeigniter/index.php/test/edit/test/update_details'". The edit_details action loads a model which then does the database stuff. The id is sent using a hidden field in the view.

我不确定这里出了什么问题。当我调用控制器时,URL似乎没有改变。它要么保持不变,要么附加到现有的URL。我曾尝试谷歌搜索解决方案,但找不到任何。

I am not sure what is going wrong here. The URL doesnt seem to change when i make calls to a controller. It either stays the same or gets appended to the existing URL. I have tried google to search for a solution but couldnt find any.

我仍然没有删除我的index.php,因为这是一个测试应用程序。
配置文件中的基本URL是: http:// localhost / codeigniter /
自动加载的帮助程序是:表单和url
自动加载的库是:数据库

I still havent removed my index.php as this is a test application. My base url in the config file is : "http://localhost/codeigniter/" Autoloaded helpers are: form and url Autoloaded libraries are: database

谢谢。

推荐答案

听起来您需要使用base_url传递回表单()。
换句话说:

It sounds like you need to pass the form back using the base_url(). In other words:

http://localhost/codeigniter/index.php/test/edit/test/update_details

是错误的。我相信您确实是在尝试将编辑视图详细信息传递给:

is wrong. I believe you are really trying to pass the edit view details to:

http://localhost/codeigniter/index.php/test/update_details

通过提交,您的网址混乱了。
您的form_open应该看起来像这样:

via submit, your url is getting messed up. Your form_open should look like this:

echo form_open(base_url()."test/update_details");

这篇关于Codeigniter中的表单操作被添加到现有URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆