How ca开发者_如何学Cn I grab this data and increment it in Codeigniter?
$_SESSION['cart'][$_GET[id]]++;
because CI destroys the $_GET array, you can do this
$_SESSION['cart'][$this->uri->segment(3)]++;
where 3 is the URL segment of the ID. But I would look in to the shopping cart class as recommended by Malachi.
from the docs ~
$data = array(
'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
'qty' => 3
);
$this->cart->update($data);
It's frowned upon, but if you really want to use the $_GET var you can always do the following:
parse_str($_SERVER['QUERY_STRING'],$_GET);
I would stick with using URI segments as shown by Ross or have the 'id' supplied as a parameter in the controller function.
maybe like this...
$cart = $this->session->userdata('cart'); $cart[$this->uri->segment(3)];
$this->input->get() is no longer messed with, so GET away.
You can do in this way.
By passing variable in your controller function, Your controller function will look like this
function my_function($id='')
{
//Your code goes here
$my_cart = $this->session->userdata('cart');
$my_data = $my_cart[$id];
}
精彩评论