Advertisement
dewa_01

Untitled

Dec 15th, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Welcome extends CI_Controller {
  4.  
  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.         $this->load->model('model_products');
  9.     }
  10.  
  11.     public function index()
  12.     {
  13.         $data['products'] = $this->model_products->all();
  14.         $this->load->view('welcome_message', $data);
  15.     }
  16.    
  17.     public function add_to_cart($product_id)
  18.     {
  19.         $product = $this->model_products->find($product_id);
  20.         $data = array(
  21.                        'id'      => $product->id,
  22.                        'qty'     => 1,
  23.                        'price'   => $product->price,
  24.                        'name'    => $product->name
  25.                     );
  26.  
  27.         $this->cart->insert($data);
  28.         redirect(base_url());
  29.     }
  30.    
  31.     public function cart(){
  32.         $this->load->view('show_cart');
  33.     }
  34.    
  35.     public function clear_cart()
  36.     {
  37.         $this->cart->destroy();
  38.         redirect(base_url());
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement