Code chức năng quản lý menu bằng php code inighter

Code chức năng quản lý menu bằng php code inighter

quản lý menu băng php code inighter

File controller menu.php

<?php
/**
 *--Project: megastore
  --Design by: ATC PRO
  -- Date time: 29/5/2022 7:41:29 PM
 * This controller handles project management.
 */
class Menu 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('Menu_model');
       
    }

    public function index()
    {
       
        $this->load->view('back_end_template/content', [
            'template' => 'backend/Menu/index','sl'=>1,
            'data' => $this->Menu_model->get_Menu()
             
        ]);
    }

	public function create()
    {
 $data = $this->Menu_model->get_where_Menu('0');
            $this->load->view('back_end_template/content', ['template' => 'backend/Menu/create','data' => $data  ]);
        
      }
    public function add()
    {
       
       
		
            $data = $this->Menu_model->create_Menu([
            'ID' => $this->input->post('ID'),
            'NAME' => $this->input->post('NAME'),
            'ALIAS' => $this->input->post('ALIAS'),
            'PARRENT' => $this->input->post('PARRENT'),
            'BLOCKID' => $this->input->post('BLOCKID'),
            'SORT' => $this->input->post('SORT'),
            'STATUS' => $this->input->post('STATUS'),
            'LINK' => $this->input->post('LINK'),
            'STYLE' => $this->input->post('STYLE'),
            'TYPE' => $this->input->post('TYPE'),
            'ItemId' => $this->input->post('ItemId'),
            'ItemName' => $this->input->post('ItemName'),
            'Position' => $this->input->post('Position'),
            'Url' => $this->input->post('Url'),
            'KEYID' => $this->input->post('KEYID'),
            'LANG' => $this->input->post('LANG'),

               
            ]);

            if ($data) {
                $this->session->set_flashdata('flash_success', 'Your Menu has been created');
				return header('location: ' .base_url().'backend/Menu/show/'.$data->ID);
            }
        
    }

	 public function search(){
        $data['template'] = 'backend/menu/index';
        $keyword = $this->input->post('keyword');   
	    $column = $this->input->post('column');   
        $list_col = array('ID' => $keyword,'NAME' => $keyword,'ALIAS' => $keyword,'PARRENT' => $keyword,'BLOCKID' => $keyword,'SORT' => $keyword,'STATUS' => $keyword,'LINK' => $keyword,'STYLE' => $keyword,'TYPE' => $keyword,'ItemId' => $keyword,'ItemName' => $keyword,'Position' => $keyword,'Url' => $keyword,'KEYID' => $keyword,'LANG' => $keyword,); 
	    if($column!="")
		{
		  $columns="Menu.$column";
		  $list_col =array($columns => $keyword);
         }
        $config['$keyword'] = $keyword;
	    $config['$columnsearch'] = $column;  
        $config['base_url'] = site_url('backend/menu/search/');
        $config['total_rows'] = $this->get_model->atc_get_count_search('Menu',$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/menu/">';
        $config['cur_tag_close'] = '</a>';
        $this->pagination->initialize($config);
        
        $data['data'] = $this->get_model->atc_get_search('Menu',$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->Menu_model->get_where_Menu($ID);
        if (!$data) {
            $this->denied_message();

           return header('location: ' .base_url().'backend/menu');
        }
        $this->load->view('back_end_template/content', [
            'template' => 'backend/menu/show',
            'data' => $data 
         
        ]);
    }

    public function edit($ID)
    {
        $data = $this->Menu_model->get_where_Menu($ID);
        if (!$data) {
            $this->denied_message();
	     	return	header('location: ' .base_url().'backend/menu');
           
        }
     
     
        
            $this->load->view('back_end_template/content', ['template' => 'backend/menu/edit', 'data' => $data ]);
       
    }

	public function update()
    {
        
            $data = [
            'ID' => $this->input->post('ID'),
            'NAME' => $this->input->post('NAME'),
            'ALIAS' => $this->input->post('ALIAS'),
            'PARRENT' => $this->input->post('PARRENT'),
            'BLOCKID' => $this->input->post('BLOCKID'),
            'SORT' => $this->input->post('SORT'),
            'STATUS' => $this->input->post('STATUS'),
            'LINK' => $this->input->post('LINK'),
            'STYLE' => $this->input->post('STYLE'),
            'TYPE' => $this->input->post('TYPE'),
            'ItemId' => $this->input->post('ItemId'),
            'ItemName' => $this->input->post('ItemName'),
            'Position' => $this->input->post('Position'),
            'Url' => $this->input->post('Url'),
            'KEYID' => $this->input->post('KEYID'),
            'LANG' => $this->input->post('LANG'),

              
            ];
		 	$ID=$this->input->post('ID');
		    $url=$this->input->post('urlre');
            if ($this->Menu_model->update_Menu( $data,$ID)) {
                $this->session->set_flashdata('flash_success', 'Your Menu has been updated');
                if($url=="save")
			   {
				   return header('location: ' .base_url().'backend/menu/');
			   }
				return header('location: ' .base_url().'backend/menu/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->Menu_model->delete_Menu($id);
					 }
					  $this->session->set_flashdata('flash_success', 'Tất cả đã xóa thành công !');
	          }
			   return  header('location: ' .base_url().'backend/menu');
	
	}
    public function delete($ID)
    {
	   if(isset($_POST['id']))
	   {
		  $ID=$_POST['id'];
	    }
        $data= $this->Menu_model->get_where_Menu($ID);
        if (!$data) {
            $this->denied_message();

          return  header('location: ' .base_url().'backend/menu');
        }
        if ($this->Menu_model->delete_Menu($ID)) {
            $this->session->set_flashdata('flash_success', 'Your Menu has been deleted');
        } else {
            $this->denied_message();
        }
         return   header('location: ' .base_url().'backend/menu');

    }

    private function denied_message()
    {
        $this->session->set_flashdata('flash_danger', 'That Menu does not exist or you do not have permission');
    }
}

File hiển thị view.php


 
 <!-- Content Header  -->
<section class="content-header">
      <h1>
       <a href="/admin/Menu/index">
         <button type="button" class="btn btn-flat btn-success"><i class="fa fa-mail-reply-all"></i>&nbsp;Trở về</button>
       </a>
 Menu Index
        
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Menu</a></li>
        <li class="active"> Menu 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> Menu Index</h3>
                </div>
              <div class="box-body">
<form action='<?=base_url()?>backend/menu/Add' method='post' id='form_menu'>
<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>
  <textarea class="form-control" id="NAME"  required='required'  name="NAME" cols="20" rows="2"><?php if(isset($data[0]->NAME)) echo $data[0]->NAME;?></textarea>
  </div>
    <div class="form-group">
    <label for="Input_ALIAS">ALIAS</label>
  <textarea class="form-control" id="ALIAS"  required='required'  name="ALIAS" cols="20" rows="2"><?php if(isset($data[0]->ALIAS)) echo $data[0]->ALIAS;?></textarea>
  </div>
    <div class="form-group">
    <label for="Input_PARRENT">PARRENT</label>
  <input  placeholder="PARRENT" class="form-control" id="PARRENT" name="PARRENT"   required='required'   value='<?php if(isset($data[0]->PARRENT)) echo $data[0]->PARRENT;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_BLOCKID">BLOCKID</label>
  <input  placeholder="BLOCKID" class="form-control" id="BLOCKID" name="BLOCKID"   required='required'   value='<?php if(isset($data[0]->BLOCKID)) echo $data[0]->BLOCKID;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_SORT">SORT</label>
  <input  placeholder="SORT" class="form-control" id="SORT" name="SORT"   required='required'   value='<?php if(isset($data[0]->SORT)) echo $data[0]->SORT;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_STATUS">STATUS</label>
  <input  class="form-control" id="STATUS" name="STATUS"  required='required'  type="checkbox" value="STATUS" style='display:block'  />
  </div>
    <div class="form-group">
    <label for="Input_LINK">LINK</label>
  <textarea class="form-control" id="LINK"  required='required'  name="LINK" cols="20" rows="2"><?php if(isset($data[0]->LINK)) echo $data[0]->LINK;?></textarea>
  </div>
    <div class="form-group">
    <label for="Input_STYLE">STYLE</label>
  <input  placeholder="STYLE" class="form-control" id="STYLE" name="STYLE"   required='required'   value='<?php if(isset($data[0]->STYLE)) echo $data[0]->STYLE;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_TYPE">TYPE</label>
  <input  placeholder="TYPE" class="form-control" id="TYPE" name="TYPE"   required='required'   value='<?php if(isset($data[0]->TYPE)) echo $data[0]->TYPE;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_ItemId">ItemId</label>
  <input  placeholder="ItemId" class="form-control" id="ItemId" name="ItemId"   required='required'   value='<?php if(isset($data[0]->ItemId)) echo $data[0]->ItemId;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_ItemName">ItemName</label>
  <input  placeholder="ItemName" class="form-control" id="ItemName" name="ItemName"   required='required'   value='<?php if(isset($data[0]->ItemName)) echo $data[0]->ItemName;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_Position">Position</label>
  <input  placeholder="Position" class="form-control" id="Position" name="Position"   required='required'   value='<?php if(isset($data[0]->Position)) echo $data[0]->Position;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_Url">Url</label>
  <textarea class="form-control" id="Url"  required='required'  name="Url" cols="20" rows="2"><?php if(isset($data[0]->Url)) echo $data[0]->Url;?></textarea>
  </div>
    <div class="form-group">
    <label for="Input_KEYID">KEYID</label>
  <input  placeholder="KEYID" class="form-control" id="KEYID" name="KEYID"   required='required'   value='<?php if(isset($data[0]->KEYID)) echo $data[0]->KEYID;?>'  type="text" >
  </div>
    <div class="form-group">
    <label for="Input_LANG">LANG</label>
  <input  placeholder="LANG" class="form-control" id="LANG" name="LANG"   required='required'   value='<?php if(isset($data[0]->LANG)) echo $data[0]->LANG;?>'  type="text" >
  </div>

<div class="box-footer"> <button type="submit" class="btn btn-primary">Save changes</button></div>
</form>
              </div>
            </div>
        </div>
      </div>
 </section>

File model.php

<?php

/**
 *--Project: megastore
  --Design by: ATC PRO
  -- Date time: 29/5/2022 7:42:58 PM
 */
class Menu_model extends CI_Model
{
    public function create_Menu($data)
    {
        $this->db->insert('Menu', $data);
		$id=$this->db->insert_id();
		if($id==0)
		{
		    return base_url().'backend/Menu';
		}
        return $this->db->get_where('Menu', ['ID' => $id])->row();
    }

    public function get_Menu()
    {
	    $this->db->select('Menu'.'.*', FALSE);
        $this->db->from('Menu');
	    $query = $this->db->get();  
        return $query->result();
        
    }
	public function get_where_Menu($ID)
    {
        return $this->db->get_where('Menu', ['ID' => $ID])->result();
    }

    public function get_Menu_where( $ID)
    {
        return $this->db->get_where('Menu', ['ID' => $ID])->row();
    }

    public function update_Menu( $data, $ID)
    {
        return $this->db->where(['ID' => $ID])->update('Menu', $data);
    }

    public function delete_Menu( $ID)
    {
       
        return $this->db->where(['ID' => $ID])->delete('Menu');
    }

    
}

 


Tags

admin

Hãy chia sẽ cảm nghĩ của bạn về bài viết trên nhé !

Code Block menu năng khối menu bằng php Đọc tin trước

Code Block menu năng khối menu bằng php

 Manager Oder cart bằng lavarel Đọc tin kế

Manager Oder cart bằng lavarel

0 Nhận xét

  • Hãy trở thành người đầu tiên viết chia sẽ cảm nghĩ của mình bên dưới nhé!

Thêm Bình luận