0

我很好奇为什么当我 print_r($this->input->post()) 时,它会打印一个数组,然后在它之后有 1。这是它打印的内容:

Array ( [username] => lilmousiee [birthdate] => 1992-04-26 [gender] => 1 [password] => 66lah66lab [password2] => 66lah66lab [pin] => 2323 [pin2] => 2323 [email] => mouseywings@live.com [email2] => mouseywings@live.com [region] => 1 [dtype] => air [dname] => Mattyco [dgender] => 1 [terms] => [recaptcha_challenge_field] => 03AHJ_VutHNI6hK3M_trpE-n4Qr9V5wWSH10p8hmQjrYVLeWf65ylIDva5XdH78uGED5KCsMx8tp3FHZ6p1xTllyrdSP7nEbnSILQ9CDqrxoD2pit5o9T9Cowy06_O6XLLM22fvH_5ICqoYrmI-o-P8dGCal0fNKuSohgvFU03FmgbhuYTDjJ_xUA [recaptcha_response_field] => asdfsadf [submit] => Register [search] => [type] => usersitems ) 1

为什么在数组之后打印“1”?我什至没有输入...并且在注册按钮之后没有输入字段的值为 1...“搜索”和“类型”键到底是什么?

我的 HTML 的最后一部分:

    <legend>Terms of Use</legend>
    <div id="terms">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae turpis ut sem tristique luctus. Sed tincidunt consequat tristique. Mauris laoreet vestibulum aliquam. Ut enim tortor, aliquet at faucibus sed, venenatis eget tellus. Praesent velit nisl, bibendum a dignissim nec, hendrerit non lacus. Fusce dapibus pharetra molestie. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae turpis ut sem tristique luctus. Sed tincidunt consequat tristique. Mauris laoreet vestibulum aliquam. Ut enim tortor, aliquet at faucibus sed, venenatis eget tellus. Praesent velit nisl, bibendum a dignissim nec, hendrerit non lacus. Fusce dapibus pharetra molestie. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae turpis ut sem tristique luctus. Sed tincidunt consequat tristique. Mauris laoreet vestibulum aliquam. Ut enim tortor, aliquet at faucibus sed, venenatis eget tellus. Praesent velit nisl, bibendum a dignissim nec, hendrerit non lacus. Fusce dapibus pharetra molestie. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae turpis ut sem tristique luctus. Sed tincidunt consequat tristique. Mauris laoreet vestibulum aliquam. Ut enim tortor, aliquet at faucibus sed, venenatis eget tellus. Praesent velit nisl, bibendum a dignissim nec, hendrerit non lacus. Fusce dapibus pharetra molestie. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
    </div>
    <?php echo form_checkbox(array('name' => 'terms')); ?> Accept Terms of Use
    <div class="row clearfix">
        <?php
          echo recaptcha_get_html($public_key);
        ?>
    </div>
</fieldset>
<?php echo print_r($array); ?>

<div class="row clearfix"><?php echo form_submit('submit', 'Register'); ?></div>
<? echo form_close(); ?>

我只是无法将 $this->input->post() 数组传递给验证函数。这是我的库文件夹中的 MY_Form_validation.php:

class MY_Form_validation extends CI_Form_validation {
    private $post;

    public function __construct($params = array()) {
        foreach($params as $param) {
        parent::__construct($param['config']);
$this->post = $param['post'];
        }

    }
}

是否有理由将“1”打印为 $this->post 值...何时应该保存数组的键和值?这就是我传递参数的方式:

$this->load->library('MY_Form_validation', array('config' => '', 'post' => $this->input->post()));

但是当我输入 print_r($this->post) 时,它只打印“1”..

4

2 回答 2

1

这是因为$this->input->post()是一个对象,而不是字符串或数组。它打印出 1 因为该对象存在并且具有属性。如果它不存在或为空,它将打印 0。它只是布尔返回值的数字表示。

正如有人提到的那样,如果这样做,var_dump($this->input->post())您将不会出现“1”字符。

要获取字段的值,请在括号中指定字段名称:

$recaptcha_data = $this->input->post('recaptcha_challenge_field');

另一个澄清;您可以$this->input->post()像这样使用 ' 的返回值:

if ($this->input->post()) 
{
    // do stuff if post array exists
}
于 2012-12-13T22:37:52.580 回答
1

这是因为你用过

<?php echo print_r($array); ?>

print_r() 将打印数组并返回 1。Echo 将在打印您可以使用的数组后显示此 1

<?php print_r($array); ?>
于 2013-08-07T06:26:32.717 回答