我的app中有以下codeigniter代码100%正常工作,但我不知道原因。
我的控制器语法的一部分
if($this->input->post()){
$data = array(
'customer' =>$this->input->post('customer'),
'period' =>$this->input->post('period'),
'buom' =>$this->input->post('buom'),
// 'creditlimit' =>$this->input->post('buom'),
'creditlimit' => $this->sales_model->get_creditlimit($this->input->post('customer'))
);
$this->session->set_userdata($data);
}
$this->load->view('sales/new_blank_order_lines',$this->session->all_userdata());
我不理解set_userdata($data);
和$this->session->all_userdata()
set_userdata
到all_userdata
提前致谢。
答案 0 :(得分:3)
正如文件所说:
for all_userdata:
$this->session->all_userdata()
表示所有可用数据都放在这样的数组中。
Array
(
[session_id] => 4a5a5dca22728fb0a84364eeb405b601
[ip_address] => 127.0.0.1
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7;
[last_activity] => 1303142623
)
for set_userdata:
添加自定义会话数据
会话数组的一个有用方面是您可以添加自己的数据 它将存储在用户的cookie中。你为什么想要 去做这个?这是一个例子:
假设某位特定用户登录您的网站。经过身份验证后, 您可以将他们的用户名和电子邮件地址添加到会话cookie中, 无需运行即可全局使用这些数据 您需要时进行数据库查询。
要将数据添加到会话数组涉及传递数组 将新数据包含在此函数中:
$this->session->set_userdata($array);
其中$ array是包含新数据的关联数组。这是一个例子:
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe@some-site.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
了解更多HERE
答案 1 :(得分:1)
* all_userdata *返回所有userdata的数组,它将返回如下内容:
Array
(
[session_id] => 4a5a5dca22728fb0a84364eeb405b601
[ip_address] => 127.0.0.1
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7;
[last_activity] => 1303142623
)
* set_userdata *设置自定义会话数据。
这可行的原因是因为CodeIgniter能够通过* all_userdata *
识别您的会话希望这有帮助,不要犹豫,提出进一步的问题=)
答案 2 :(得分:1)
在顶部添加对我的评论的引用
$data = array();
if($this->input->post()){
$data = array(
'customer' =>$this->input->post('customer'),
'period' =>$this->input->post('period'),
'buom' =>$this->input->post('buom'),
// 'creditlimit' =>$this->input->post('buom'),
'creditlimit' => $this->sales_model->get_creditlimit($this->input->post('customer'))
);
}
if(count($data)>0)
{
$this->load->view('sales/new_blank_order_lines',$data);
}
else
{
$this->load->view('sales/new_blank_order_lines');
}