POST变量为空

时间:2011-03-04 23:54:36

标签: php codeigniter

我有以下控制器文件:

<?php
class Test extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();  
    }

    function index()
    {   
        print_r($_POST);
        $view_params = array();

        $this->load->view('test', $view_params);
    }
}
?>

视图文件为:

<form action="/test" method="post">
    <input type="text" name="test" />
    <input type="submit" />
</form>

<ul id="account">
    <li class="separator url"><label>Domain Address (URL)</label><input maxlength="22" type="text" name="sub_url" />
    <small class="subtext">This is the link people use to find your site. You can change this at any time.</small>
</li>
</ul>
<img class="green_arrow" src="assets/images/green_arrow.png" />

当我点击提交按钮时,没有任何帖子数据被吐出,但是当我进行页面刷新时,它表示数据已经发布并将重新发送。

另外,我认为html只是一个片段,但请理解我正在尝试减少代码,从而减少问题区域的数量。之后有那么多垃圾的原因是因为如果我删除了视图文件停止工作,但这是另一个问题。

2 个答案:

答案 0 :(得分:2)

出于安全考虑,CodeIgniter会清空$ _POST,$ _GET等。改为使用Input类。

$post = $this->input->post();

$some_data = $this->input->post('some_data');

请阅读: http://codeigniter.com/user_guide/libraries/input.html

答案 1 :(得分:1)

嘿Johnathan,我很高兴我能解决你的问题。你所要做的就是启用apache的mod重写。

a2enmod rewrite 
/etc/init.d/apache2 reload

因为你没有apache的mod重写,代码点火器必须搞砸了一些重写规则,并在帖子后面弄乱你的表单数据。