代码点火器POST变量 [英] Code Igniter POST Variable

查看:41
本文介绍了代码点火器POST变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Code Igniter的新手,但我似乎无法在文档中找到实现此目的的方法,在普通的PHP中,您可以像这样检索整个POST变量的内容

I am brand new to Code Igniter but I can't seem to find a way to do this in the documentation, In normal PHP you can retrieve the contents of the entire POST variable like this

$ _ POST = $ postedVars

但是,我似乎无法找到以相同方式执行此操作的东西

But I can't seem to find something that does this in the same manner, I've tried

$ arr = $ this-> input-> post;

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

没有运气!在CI中这可能吗?预先感谢!

With no luck! Is this possible in CI? Thanks in advance!

推荐答案

首先,您需要一种用于设置变量的表单或其他内容然后,您检索它们.

First, you need a form or something that sets the variables Then, you retrieve them.

$ this-> input-> post('first_name').

$this->input->post('first_name').

您缺少该变量的名称!

注册表单:

echo form_open('CHome/signup');
$data=array('name'=>'first_name', 'id'=>'first_name','size'=>40,'value'=>set_value('first_name'));
echo "<p><label for='first_name'>First Name </label>";
echo form_input($data);
echo form_submit('submit','Make Account');

模型:

 function addUser(){
    //you should use $this->input->post('first_name')
            $data=array(
                'first_name'=>db_clean(ucfirst($_POST['first_name'])), //db_clean is a custom func
                'last_name'=>db_clean(ucfirst($_POST['last_name'])),        
                'email'=>db_clean($_POST['email']),            
                'username'=>db_clean($_POST['username']),
                'password'=>db_clean(sha1($_POST['password1'])),            
                'type'=>db_clean('user'),
            );

            $this->db->insert('users',$data);
        }

Codeigniter将会话存储在cookie中,这很奇怪.我建议仅使用PHP的本机会话,例如$ _SESSION ['first_name'].确保写"session_start();"在您的控制器/模型中,以便您可以使用会话!(通常是在构造函数中完成)

Codeigniter stores sessions in cookies, it's all weird. I suggest just using PHP's native sessions, such as $_SESSION['first_name']. Make sure to write "session_start();" in your controller/model so you can use sessions!! (usually do it in the constructor)

这篇关于代码点火器POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆