CODEIGNITER + BOOTSTRAP

MENGGUNAKAN BOOTSTRAP PADA CODEIGNITER



Karina Soraya P
05111740000003
PWEB - C


Tutorial pembuatannya bisa dilihat di link berikut :

Berikut Source Code intinya :

  • Source Code overview.php
 <!DOCTYPE html>  
 <html lang="en">  
 <head>  
  <?php $this->load->view("admin/_partials/head.php") ?>  
 </head>  
 <body id="page-top">  
 <?php $this->load->view("admin/_partials/navbar.php") ?>  
 <div id="wrapper">  
  <?php $this->load->view("admin/_partials/sidebar.php") ?>  
  <div id="content-wrapper">  
   <div class="container-fluid">  
     <!--  
     karena ini halaman overview (home), kita matikan partial breadcrumb.  
     Jika anda ingin mengampilkan breadcrumb di halaman overview,  
     silahkan hilangkan komentar (//) di tag PHP di bawah.  
     -->  
   <?php //$this->load->view("admin/_partials/breadcrumb.php") ?>  
   <!-- Icon Cards-->  
   <div class="row">  
    <div class="col-xl-3 col-sm-6 mb-3">  
    <div class="card text-white bg-primary o-hidden h-100">  
     <div class="card-body">  
     <div class="card-body-icon">  
      <i class="fas fa-fw fa-comments"></i>  
     </div>  
     <div class="mr-5">26 New Messages!</div>  
     </div>  
     <a class="card-footer text-white clearfix small z-1" href="#">  
     <span class="float-left">View Details</span>  
     <span class="float-right">  
      <i class="fas fa-angle-right"></i>  
     </span>  
     </a>  
    </div>  
    </div>  
    <div class="col-xl-3 col-sm-6 mb-3">  
    <div class="card text-white bg-warning o-hidden h-100">  
     <div class="card-body">  
     <div class="card-body-icon">  
      <i class="fas fa-fw fa-list"></i>  
     </div>  
     <div class="mr-5">11 New Tasks!</div>  
     </div>  
     <a class="card-footer text-white clearfix small z-1" href="#">  
     <span class="float-left">View Details</span>  
     <span class="float-right">  
      <i class="fas fa-angle-right"></i>  
     </span>  
     </a>  
    </div>  
    </div>  
    <div class="col-xl-3 col-sm-6 mb-3">  
    <div class="card text-white bg-success o-hidden h-100">  
     <div class="card-body">  
     <div class="card-body-icon">  
      <i class="fas fa-fw fa-shopping-cart"></i>  
     </div>  
     <div class="mr-5">123 New Orders!</div>  
     </div>  
     <a class="card-footer text-white clearfix small z-1" href="#">  
     <span class="float-left">View Details</span>  
     <span class="float-right">  
      <i class="fas fa-angle-right"></i>  
     </span>  
     </a>  
    </div>  
    </div>  
    <div class="col-xl-3 col-sm-6 mb-3">  
    <div class="card text-white bg-danger o-hidden h-100">  
     <div class="card-body">  
     <div class="card-body-icon">  
      <i class="fas fa-fw fa-life-ring"></i>  
     </div>  
     <div class="mr-5">13 New Tickets!</div>  
     </div>  
     <a class="card-footer text-white clearfix small z-1" href="#">  
     <span class="float-left">View Details</span>  
     <span class="float-right">  
      <i class="fas fa-angle-right"></i>  
     </span>  
     </a>  
    </div>  
    </div>  
   </div>  
   <!-- Area Chart Example-->  
   <div class="card mb-3">  
    <div class="card-header">  
    <i class="fas fa-chart-area"></i>  
    Visitor Stats</div>  
    <div class="card-body">  
    <canvas id="myAreaChart" width="100%" height="30"></canvas>  
    </div>  
    <div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>  
   </div>  
   </div>  
   <!-- /.container-fluid -->  
   <!-- Sticky Footer -->  
   <?php $this->load->view("admin/_partials/footer.php") ?>  
  </div>  
  <!-- /.content-wrapper -->  
 </div>  
 <!-- /#wrapper -->  
 <?php $this->load->view("admin/_partials/scrolltop.php") ?>  
 <?php $this->load->view("admin/_partials/modal.php") ?>  
 <?php $this->load->view("admin/_partials/js.php") ?>  
 </body>  
 </html>  
  • Source Code product_model.php
 <?php defined('BASEPATH') OR exit('No direct script access allowed');  
 class Product_model extends CI_Model  
 {  
   private $_table = "products";  
   public $product_id;  
   public $name;  
   public $price;  
   public $image = "default.jpg";  
   public $description;  
   public function rules()  
   {  
     return [  
       ['field' => 'name',  
       'label' => 'Name',  
       'rules' => 'required'],  
       ['field' => 'price',  
       'label' => 'Price',  
       'rules' => 'numeric'],  
       ['field' => 'description',  
       'label' => 'Description',  
       'rules' => 'required']  
     ];  
   }  
   public function getAll()  
   {  
     return $this->db->get($this->_table)->result();  
   }  
   public function getById($id)  
   {  
     return $this->db->get_where($this->_table, ["product_id" => $id])->row();  
   }  
   public function save()  
   {  
     $post = $this->input->post();  
     $this->product_id = uniqid();  
     $this->name = $post["name"];  
     $this->price = $post["price"];  
     $this->description = $post["description"];  
     $this->image = $this->_uploadImage();  
     $this->db->insert($this->_table, $this);  
   }  
   public function update()  
   {  
     $post = $this->input->post();  
     $this->product_id = $post["id"];  
     $this->name = $post["name"];  
     $this->price = $post["price"];  
     if (!empty($_FILES["image"]["name"])) {  
       $this->image = $this->_uploadImage();  
     } else {  
       $this->image = $post["old_image"];  
     }  
     $this->description = $post["description"];  
     $this->db->update($this->_table, $this, array('product_id' => $post['id']));  
   }  
   public function delete($id)  
   {  
     return $this->db->delete($this->_table, array("product_id" => $id));  
   }  
   private function _uploadImage()  
   {  
     $config['upload_path']     = './upload/product/';  
     $config['allowed_types']    = 'gif|jpg|png';  
     $config['file_name']      = $this->product_id;  
     $config['overwrite']      = true;  
     $config['max_size']       = 1024; // 1MB  
     // $config['max_width']      = 1024;  
     // $config['max_height']      = 768;  
     $this->load->library('upload', $config);  
     if ($this->upload->do_upload('image')) {  
       return $this->upload->data("file_name");  
     }  
     return "default.jpg";  
   }  
   private function _deleteImage($id)  
   {  
     $product = $this->getById($id);  
     if ($product->image != "default.jpg") {  
       $filename = explode(".", $product->image)[0];  
       return array_map('unlink', glob(FCPATH."upload/product/$filename.*"));  
     }  
   }  
 }  
  • Source Code products.php
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Products extends CI_Controller  
 {  
   public function __construct()  
   {  
     parent::__construct();  
     $this->load->model("product_model");  
     $this->load->library('form_validation');  
   }  
   public function index()  
   {  
     $data["products"] = $this->product_model->getAll();  
     $this->load->view("admin/product/list", $data);  
   }  
   public function add()  
   {  
     $product = $this->product_model;  
     $validation = $this->form_validation;  
     $validation->set_rules($product->rules());  
     if ($validation->run()) {  
       $product->save();  
       $this->session->set_flashdata('success', 'Berhasil disimpan');  
     }  
     $this->load->view("admin/product/new_form");  
   }  
   public function edit($id = null)  
   {  
     if (!isset($id)) redirect('admin/products');  
     $product = $this->product_model;  
     $validation = $this->form_validation;  
     $validation->set_rules($product->rules());  
     if ($validation->run()) {  
       $product->update();  
       $this->session->set_flashdata('success', 'Berhasil disimpan');  
     }  
     $data["product"] = $product->getById($id);  
     if (!$data["product"]) show_404();  
     $this->load->view("admin/product/edit_form", $data);  
   }  
   public function delete($id=null)  
   {  
     if (!isset($id)) show_404();  
     if ($this->product_model->delete($id)) {  
       redirect(site_url('admin/products'));  
     }  
   }  
 }  
  • Hasil Implementasi
Bentuk Halaman Admin


Ketika akan menambahkan product


Setelah product ditambahkan



Komentar

Postingan Populer