无论我通过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
?
- 我
- 尝试设置我的所有
uri_protocol
设置。 - 在
''
和'index.php'
上尝试了CodeIgniter配置index_page
- 尝试了很多不同的.htaccess方法。
- 检查我的 apache
mod_rewrite
是否包含在/允许,它是。 - 选中允许重写是否设置为在 apache/conf/httpd.conf 中尽可能
All
- 试图用
$this->input->post()
阅读$_POST
- 使行动路径绝对,仍然什么都没有。
- 已尝试从外部脚本发布到代码点火器索引.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
.
对于想要查看控制器(身份验证.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');
}
}
尝试此操作 删除您的操作并添加 enctype
<form name="login" id="login" action="" method="post" enctype="multipart/form-data">
<input type='submit' name='login' value='TEST' />
</form>
并在您的控制器中
在当前操作中添加以下代码。
if($this->input->post()){
echo "<pre>";print_r($this->input->post());die;
}
这是我的解决方案:
我对CI_Model进行了覆盖,以始终检查是否有$this->input->post('login')
,如果是,请检查是否发布了用户并通过验证。如果未验证redirect
登录页面。那个redirect
正在清除我所有的帖子。
感谢所有试图提供帮助的人,我深表歉意。