CodeIgniter 表单提交重定向到本地主机
我有一个 CodeIgniter 项目,其中有一个非常简单的测试应用程序。
控制器打开一个视图(PHP 页面),其中有一个文本框和一个提交按钮。 当我按下提交按钮时,我没有重定向到控制器中适当的函数调用,而是重定向到 localhost/xampp。
这是我认为的代码,它应该重定向到名为“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>
有什么想法可能是错的吗?我认为这不是代码,而是某个地方的设置或文件错误,但我不知道从哪里开始寻找。
编辑:
- 我已经在配置文件中重新定义了基本 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>
编辑: 好的 - 我自己重新创建了该项目,然后将我的 PHP 文件引入,它工作正常。所以创建这个项目的人做了一些奇怪的事情。
I have a CodeIgniter project with a very simple test application.
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.
here's the code on my view, which SHOULD be redirecting to the save_genre function in the controller named "welcome".
<?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!
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
/system/application/config/config.php
中编辑$config['base_url']
。You need to edit
$config['base_url']
in/system/application/config/config.php
.不知何故,虽然index.php 文件存在于文件系统中,但它没有被识别为项目的一部分。一旦我在那里复制了一个新的index.php文件(相同的文件,但它触发了“这发生了变化”的感觉),然后我回到我的项目并刷新并保存。
然后一切都工作了。
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.
Everything then worked.