1. LOAD Library
1 |
$autoload['libraries'] = array('database', 'table', 'cart'); |
2. MUST set an encryption key
1 |
$config['encryption_key'] = '1234567890'; |
Create a new file in a folder -> Controller
1 |
/application/controller/cart.php |
Write Code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Cart extends CI_Controller { function add() { $data = array( 'id' => '42', 'name' => 'Pants', 'qty' => 1, 'price' => 20.00, 'options' => array('Size' => 'Medium') ); $this->cart->insert($data); echo "add() Ok"; } function show() { $cart = $this->cart->contents(); echo "<pre>"; print_r($cart); } function add2() { $data = array( 'id' => '10', 'name' => 'T-shirt', 'qty' => 2, 'price' => 10.00, 'options' => array('Size' => 'Small') ); $this->cart->insert($data); echo "add2() Ok"; } function update() { $data = array( 'rowid' => '4e3a5699b06bcc223ef814bd88249cc0', 'qty' => 5 ); $this->cart->update($data); echo "update() Ok"; } function total() { echo $this->cart->total(); } function remove() { $data = array( 'rowid' => '4e3a5699b06bcc223ef814bd88249cc0', 'qty' => 0 ); $this->cart->update($data); echo "remove() Ok"; } function destroy() { $this->cart->destroy(); echo "destroy() Ok"; } } |