我的问题很简单:我的表中有一个名为credit
的字段。
我想向连接的用户添加1 credit
,所以我更新了字段credit
。更新效果很好,但是当我要显示credit
时,添加操作尚未完成。
示例:用户Joe
已用2 credit
登录。我加他1 credit
。它可以在数据库中工作,但不能在屏幕上工作。如果他断开连接并重新连接,问题就解决了。
所以,我想知道如何在不断开连接的情况下更新会话数据
Controller'LoginArea'
$this->load->library('session');
$dataUser = array(
'id' => $ligneBDD->{'id_user'},
'name' => $ligneBDD->{'name'},
'credit' => $ligneBDD->{'credit'}
);
// i store id, name and credit in my session
$this->session->set_userdata('data', $dataUser);
这是我的更新:
$update= $this->User_model->update(array(
'credit' => $userConnected['credit'] - 1
),
array(
'id_user' => $userConnected['id'])
);
您需要将会话视为特定用户的(临时)“状态”。
如果执行登录(LoginArea),将从数据库(DB permanent存储/状态)中获取当前的用户数据(和信用)。然后,此userData将保存在会话中。
但是会话和数据库都被分隔并且未连接。
因此,如果您更改数据库,则此更改不会反映在会话中,反之亦然。
现在更新数据库时,您也需要更新会话。因此,这里有两个可能的解决方案:
credit
属性,然后再次将其保存在会话中(覆盖)==>新的(更新的)数据将出现在Session-UserData中