好的,所以這一個困惑我。在會話中設置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