apache CodeIgniter 表单提交重定向到本地主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2083800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter form submit redirects to localhost
提问by user158017
I have a CodeIgniter project with a very simple test application.
我有一个带有非常简单的测试应用程序的 CodeIgniter 项目。
Controller opens a view (PHP page) which has a text box and a submit button. When I press the submit button, instead of redirecting to the appropriate function call in the controller, I get redirected to localhost/xampp.
控制器打开一个视图(PHP 页面),其中有一个文本框和一个提交按钮。当我按下提交按钮时,我没有重定向到控制器中的适当函数调用,而是重定向到 localhost/xampp。
here's the code on my view, which SHOULD be redirecting to the save_genre function in the controller named "welcome".
这是我视图中的代码,它应该重定向到名为“welcome”的控制器中的 save_genre 函数。
<?php echo form_open('welcome/save_genre');?>
<label for="radio_genre">Radio Genre</label>
<input type="text" name="radio_genre" id="radio_genre"></input>
<?php echo form_submit('submit','Save'); ?>
</form>
any ideas what could be wrong? I think it's not the code but is a setting or file wrong somewhere, but i don't know where to start looking.
任何想法可能是错误的?我认为这不是代码,而是某处的设置或文件错误,但我不知道从哪里开始寻找。
EDIT:
编辑:
- I had already redefined the base URL in the config file.
- I don't think I rewrote the .htaccess - but I'll certainly check. (This is a team project setup and I'll make sure no one else has done that.)
- As requested, below is the HTML output by the form. The URL link for the form seems very odd to me because it doesn't mention the project name like I would expect. So there are two places for me to look now. Thanks!
- 我已经在配置文件中重新定义了基本 URL。
- 我不认为我重写了 .htaccess - 但我肯定会检查。(这是一个团队项目设置,我会确保没有其他人这样做过。)
- 根据要求,以下是表单的 HTML 输出。表单的 URL 链接对我来说似乎很奇怪,因为它没有像我期望的那样提到项目名称。所以我现在有两个地方可以看。谢谢!
<body>
<h1>Welcome!</h1>
<form action="http://localhost/index.php/welcome/save_genre" method="post">
<label for="radio_genre">Radio Genre</label>
<input type="text" name="radio_genre" id="radio_genre"></input>
<input type="submit" name="submit" value="Save" />
</form>
</body>
EDIT:OK - I recreated the project myself and then brought my PHP files in and it works fine. So the person who created the project did something odd.
编辑:好的 - 我自己重新创建了这个项目,然后把我的 PHP 文件带进来,它工作正常。所以创建这个项目的人做了一些奇怪的事情。
采纳答案by user158017
Somehow, while the index.php file was there in the file system, it wasn't being recognized as part of the project. Once I copied a new index.php file in there (identical file but it trigger the sense that "this changed.), I then went back into my project and refreshed and saved.
不知何故,虽然 index.php 文件存在于文件系统中,但它并未被识别为项目的一部分。一旦我在那里复制了一个新的 index.php 文件(相同的文件,但它触发了“这改变了”的感觉。),然后我回到我的项目并刷新并保存。
Everything then worked.
然后一切正常。
回答by Alix Axel
You need to edit $config['base_url']in /system/application/config/config.php.
您需要$config['base_url']在/system/application/config/config.php.

