【发布时间】:2015-02-03 09:59:57
【问题描述】:
无论我在 CodeIgniter 中通过 HTML 表单发布什么/无论如何 - 我的 $_POST 和 $_REQUEST 数组都是空的。但是,当方法设置为get 时,一切看起来都很好。
我知道我的问题与 Apache / .htaccess 或 URI 设置有关。我在 Windows 7 上运行 XAMPP。
<form method='post' action='auth/login'>
<input type='submit' name='login' value='TEST' />
</form>
现在在控制器auth 函数login 应该返回我
Array( 'login' => 'TEST' );
我得到的是
Array( );
我已经尝试过什么让它读取$_POST?
- 我已尝试设置我的 ALL
uri_protocol设置。 - 在
''和'index.php'上尝试了CodeIgniter 配置index_page - 尝试了很多不同的 .htaccess 方法。
- 检查了我的 apache
mod_rewrite是否包含/允许,并且是。 - 检查允许重写设置为
Allapache/conf/httpd.conf 中的任何地方 - 尝试用
$this->input->post()读取$_POST - 将动作路径设为绝对,还是什么都没有。
- 试图从外部脚本发布到 CodeIgniter index.php
一切都没有结果。而且我知道问题必须与 Apache 设置有关,导致所有其他没有 .htaccess 的 文件夹/项目 都可以正常工作。
所以这里是我尝试过的确切 .htaccess 内容,它在 4me 中效果最好:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] # returns 404 everywhere.
RewriteRule .* index.php/$0 [PT,L] # Pages work good!
^^ 这效果最好(至少我让网页运行)但不是$_POST。
对于那些想查看控制器(auth.php)代码的人:
class auth extends CI_Controller {
function __construct() {
# Parent constructor.
parent::__construct();
}
function login() {
# Trying to read post
print_r($_POST);
print_r($this->input->post());
# Loading form.
$this->load->view('login_page');
}
}
【问题讨论】:
-
尝试使用 form_open('auth/login') CI 表单辅助方法或
-
对于 post 不需要任何 htaccess 或删除 index.php 这是用于 preety url
-
@umefarooq 我现在尝试了你的解决方案,它最终在
action中创建了绝对路径,即localhost/auth/login,我仍然没有得到任何结果。 -
也给你发布控制器代码
-
@RakeshSharma 我现在做了,你现在想看看更新的问题 :)
标签: php apache .htaccess codeigniter mod-rewrite