Code Manager product category with theme LTE 3.X

Code Manager product category with theme LTE 3.X

Manager product category

Đầu tiên cần tạo model thao tác dữ liệu

  1. Model product.php
  2. <?php
    
    /**
     *--Project: lavarel
      --Design by: ATC PRO
      -- Date time: 26/4/2022 10:13:34 AM
     */
    class Product_categories_model extends CI_Model
    {
        public function create_Product_categories($data)
        {
            $this->db->insert('Product_categories', $data);
            $id=$this->db->insert_id();
            if($id==0)
            {
                return base_url().'backend/Product_categories';
            }
            return $this->db->get_where('Product_categories', ['id' => $id])->row();
        }
    
        public function get_Product_categories()
        {
            $this->db->select('Product_categories'.'.*', FALSE);
            $this->db->from('Product_categories');
            $query = $this->db->get();  
            return $query->result();
            
        }
        public function get_where_Product_categories($id)
        {
            return $this->db->get_where('Product_categories', ['id' => $id])->result();
        }
    
        public function get_Product_categories_where( $id)
        {
            return $this->db->get_where('Product_categories', ['id' => $id])->row();
        }
    
        public function update_Product_categories( $data, $id)
        {
            return $this->db->where(['id' => $id])->update('Product_categories', $data);
        }
    
        public function delete_Product_categories( $id)
        {
           
            return $this->db->where(['id' => $id])->delete('Product_categories');
        }
    
        
    }
    

     

Tiếp đến tạo chức năng chính

  1. Contoller product.php
  2. <?php
    /**
     *--Project: lavarel
      --Design by: ATC PRO
      -- Date time: 26/4/2022 10:11:46 AM
     * This controller handles project management.
     */
    class Product_categories extends CI_Controller
    {
        public $user_id;
        public $user_name;
    
        public function __construct(Type $foo = null)
        {
    
            parent::__construct();
            
            if (!$this->session->userdata('logged_in')) {
                $this->session->set_flashdata('flash_danger', 'Vui lòng đăng nhập để xem trang');
                header('location: ' .base_url().'backend/login');
            }
            else
            {
             $user_id = $this->session->userdata('user_id');
             $user_name = $this->session->userdata('user_name');
            
            }
            $this->load->model('product_categories_model');
           
        }
    
        public function index()
        {
           
            $this->load->view('back_end_template/content', [
                'template' => 'backend/product_categories/index','sl'=>1,
                'data' => $this->product_categories_model->get_product_categories()
                 
            ]);
        }
    
        public function create()
        {
     $data = $this->product_categories_model->get_where_product_categories('0');
                $this->load->view('back_end_template/content', ['template' => 'backend/product_categories/create','data' => $data  ]);
            
          }
        public function add()
        {
           
           
            
                $data = $this->product_categories_model->create_product_categories([
                'id' => $this->input->post('id'),
                'name' => $this->input->post('name'),
                'description' => $this->input->post('description'),
                'created_at' => $this->input->post('created_at'),
                'updated_at' => $this->input->post('updated_at'),
                'deleted_at' => $this->input->post('deleted_at'),
    
                   
                ]);
    
                if ($data) {
                    $this->session->set_flashdata('flash_success', 'Your product_categories has been created');
                    return header('location: ' .base_url().'backend/product_categories/show/'.$data->id);
                }
            
        }
    
         public function search(){
            $data['template'] = 'backend/product_categories/index';
            $keyword = $this->input->post('keyword');   
            $column = $this->input->post('column');   
            $list_col = array('id' => $keyword,'name' => $keyword,'description' => $keyword,'created_at' => $keyword,'updated_at' => $keyword,'deleted_at' => $keyword,); 
            if($column!="")
            {
              $columns="product_categories.$column";
              $list_col =array($columns => $keyword);
             }
            $config['$keyword'] = $keyword;
            $config['$columnsearch'] = $column;  
            $config['base_url'] = site_url('backend/product_categories/search/');
            $config['total_rows'] = $this->get_model->atc_get_count_search('product_categories',$list_col);
            $data['sl'] = $config['total_rows'];
            $config['per_page'] = 10;  
            $config['uri_segment'] = 3;
            $config['cur_tag_open'] = '<a class="current_page" href="backend/product_categories/">';
            $config['cur_tag_close'] = '</a>';
            $this->pagination->initialize($config);
            
            $data['data'] = $this->get_model->atc_get_search('product_categories',$list_col,$config['per_page'], $this->uri->segment($config['uri_segment'])); 
            $data['link'] = $this->pagination->create_links();
            
        
            
            $this->load->view('back_end_template/content', $data);
            
        }
        public function show($id)
        {
            $data = $this->product_categories_model->get_where_product_categories($id);
            if (!$data) {
                $this->denied_message();
    
               return header('location: ' .base_url().'backend/product_categories');
            }
            $this->load->view('back_end_template/content', [
                'template' => 'backend/product_categories/show',
                'data' => $data 
             
            ]);
        }
    
        public function edit($id)
        {
            $data = $this->product_categories_model->get_where_product_categories($id);
            if (!$data) {
                $this->denied_message();
             	return	header('location: ' .base_url().'backend/product_categories');
               
            }
         
         
            
                $this->load->view('back_end_template/content', ['template' => 'backend/product_categories/edit', 'data' => $data ]);
           
        }
    
        public function update()
        {
            
                $data = [
                'id' => $this->input->post('id'),
                'name' => $this->input->post('name'),
                'description' => $this->input->post('description'),
                'created_at' => $this->input->post('created_at'),
                'updated_at' => $this->input->post('updated_at'),
                'deleted_at' => $this->input->post('deleted_at'),
    
                  
                ];
             	$ID=$this->input->post('id');
                $url=$this->input->post('urlre');
                if ($this->product_categories_model->update_product_categories( $data,$ID)) {
                    $this->session->set_flashdata('flash_success', 'Your product_categories has been updated');
                    if($url=="save")
                   {
                       return header('location: ' .base_url().'backend/product_categories/');
                   }
                    return header('location: ' .base_url().'backend/product_categories/show/'.$ID);
                    }
               
            
        }
         public function deleteall()
        {
        
             $con = $this->input->post('id_check');
             $num_array = count($con);
    
                if($num_array>0){
                         for($i=1;$i<=$num_array;$i++)
                         {
                         $id = $con[$i-1];
                         $this->product_categories_model->delete_product_categories($id);
                         }
                          $this->session->set_flashdata('flash_success', 'Tất cả đã xóa thành công !');
                  }
                   return  header('location: ' .base_url().'backend/product_categories');
        
        }
        public function delete($id)
        {
           if(isset($_POST['id']))
           {
              $id=$_POST['id'];
            }
            $data= $this->product_categories_model->get_where_product_categories($id);
            if (!$data) {
                $this->denied_message();
    
              return  header('location: ' .base_url().'backend/product_categories');
            }
            if ($this->product_categories_model->delete_product_categories($id)) {
                $this->session->set_flashdata('flash_success', 'Your product_categories has been deleted');
            } else {
                $this->denied_message();
            }
             return   header('location: ' .base_url().'backend/product_categories');
    
        }
    
        private function denied_message()
        {
            $this->session->set_flashdata('flash_danger', 'That product_categories does not exist or you do not have permission');
        }
    }
    

     

Sau đó là hiển thị lên web

  1. View product.php
  2.  
     <!-- Content Header  -->
    <section class="content-header">
          <h1>
           <a href="/admin/product_categories/index">
             <button type="button" class="btn btn-flat btn-success"><i class="fa fa-mail-reply-all"></i>&nbsp;Trở về</button>
           </a>
     product_categories Index
            
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">product_categories</a></li>
            <li class="active"> product_categories Index</li>
          </ol>
    </section>
     <!-- Main content -->
     <section class="content">
        
      <div class="row">
      @if(ViewBag.alert!=null) {
        <div class="alert [email protected] alert-dismissible">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
    <h4><i class="icon fa [email protected]"></i> Thông báo!</h4>
      @ViewBag.alert
    </div>
    }
        <!--  column -->
         <div class="box">
            <div class="box-body">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                      <h3 class="panel-title"><i class="fa fa-plus"></i> product_categories Index</h3>
                    </div>
                  <div class="box-body">
    <form action='<?=base_url()?>backend/product_categories/Add' method='post' id='form_product_categories'>
    <div class="box-body">
    <input   id='urlre' value='' name='urlre'  type='hidden'  />    <div class="form-group">
        <label for="Input_id">id</label>
      <input  placeholder="id" class="form-control" id="id" name="id"   required='required' value='<?php if(isset($data[0]->id)) echo $data[0]->id;?>' type="text" >
      </div>
        <div class="form-group">
        <label for="Input_name">name</label>
      <input  placeholder="name" class="form-control" id="name" name="name"   required='required'   value='<?php if(isset($data[0]->name)) echo $data[0]->name;?>'  type="text" >
      </div>
        <div class="form-group">
        <label for="Input_description">description</label>
      <textarea  class="form-control" id="description" name="description" placeholder=" required='required' " ><?php if(isset($data[0]->description)) echo $data[0]->description;?></textarea>
    <script type='text/javascript'>
                	    CKEDITOR.replace( 'description',{
                	    height : '250'
                		
                	});		
                </script>  </div>
        <div class="form-group">
        <label for="Input_created_at">created_at</label>
      <input  placeholder="created_at" class="form-control" id="created_at" name="created_at"   required='required'   value='<?php if(isset($data[0]->created_at)) echo $data[0]->created_at;?>'  type="text" >
      </div>
        <div class="form-group">
        <label for="Input_updated_at">updated_at</label>
      <input  placeholder="updated_at" class="form-control" id="updated_at" name="updated_at"   required='required'   value='<?php if(isset($data[0]->updated_at)) echo $data[0]->updated_at;?>'  type="text" >
      </div>
        <div class="form-group">
        <label for="Input_deleted_at">deleted_at</label>
      <input  placeholder="deleted_at" class="form-control" id="deleted_at" name="deleted_at"   required='required'   value='<?php if(isset($data[0]->deleted_at)) echo $data[0]->deleted_at;?>'  type="text" >
      </div>
    
    <div class="box-footer"> <button type="submit" class="btn btn-primary">Save changes</button></div>
    </form>
                  </div>
                </div>
            </div>
          </div>
     </section>
    
    

     

nguyen tran

Leave a Reply

Your email address will not be published. Required fields are marked *