Session 在CodeIgniter中使用会话库
由于某些原因,我很难理解CI中的会话是如何工作的。Session 在CodeIgniter中使用会话库,session,codeigniter,Session,Codeigniter,由于某些原因,我很难理解CI中的会话是如何工作的。 我想将下面的代码部分改为使用CodeIgniter会话,而不是PHP中通常的方式。最好的方法是什么 foreach($_POST['qty'] as $k => $v) { $id = (int)$k; $qty = (int)$v; $_SESSION['cart'][$id]['quantity'] = $qty; } 还有一个问题 在使用CI会话库时,当会话具有多维结构时,在读取所需的值之前,是否总是必须
我想将下面的代码部分改为使用CodeIgniter会话,而不是PHP中通常的方式。最好的方法是什么
foreach($_POST['qty'] as $k => $v) {
$id = (int)$k;
$qty = (int)$v;
$_SESSION['cart'][$id]['quantity'] = $qty;
}
还有一个问题在使用CI会话库时,当会话具有多维结构时,在读取所需的值之前,是否总是必须先将会话的内容放到数组中?我会这样做
// Fetch the cart from the session
$cart = $this->session->userdata('cart');
// Update the cart
foreach ($this->input->post('qty') as $k => $v)
{
$id = (int) $k;
$qty = (int) $v;
$cart[$id]['quantity'] = $qty;
}
// Save the cart back to the session
$this->session->set_userdata('cart', $cart);
谢谢这看起来很合理,我要试一试。