好的,所以这一个困惑我。在会话中设置user_data给出不同的结果
当我在用户登录设置在会话中的用户数据,像这样:
$data = array();
$data['email'] = $this->input->post('email');
// get the user's info where it matches their email in the db.
$user = $this->User_model->get_user($data);
$this->session->set_userdata('user_session', $user);
现在这个伟大的工程。它在会话数据中创建user_session
作为对象。我可以。
然后当用户更新他们的信息时,我想重置user_session
中的数据以匹配他们的新数据。我这样做,像这样:
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('phone'),
'street1' => $this->input->post('street1'),
'street2' => $this->input->post('street2'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'zip' => $this->input->post('zip'),
'password' => $encrypted_password,
'organizations_id' => $this->input->post('org_select')
);
$user = $this->User_model->get_user($data);
$this->session->set_userdata('user_session', $data);
现在,这里的$data
被用来更新自己的DB信息,然后我再用它在他们email
拉他们出来的数据通过索引。
最后,这里是我使用他们两人的模型方法:
public function get_user($data)
{
return $this->db
->where('email', $data['email'])
->select('first_name, last_name, email, password, id, organizations_id')
->get('users')
->row();
}
这工作,但方式不同。与其给我一个对象,它只是给了我一个数组。这导致了我的代码中其他地方的很多问题。
如何控制是否它给我一个对象或数组?
编辑:
我意识到白痴的举动。当用户更改其信息时,我将$data
而不是$user
发送给我的模型。
所以我解决了这个问题,现在我得到一个对象两次。但我仍然想知道这两种方法如何产生不同的结果。这样我可以在将来控制它。
所以他这样说,这里是我的官问:
我如何控制会话数据的输入,所以它是数组或对象?
这实际上是一个非常好的主意。它是否必须是随机字符串?或者我可以在数据库中使用自动递增的数字(也就是说,它现在是如何设置的,每个用户都有自己的唯一编号,但它不是随机的) – JDillon522
在编辑中回复 – cartalot