Cate code CI_Controller trong codeinighter

Cate code CI_Controller trong codeinighter
<?php
/**
 *--Project: lavarel
  --Design by: ATC PRO
  -- Date time: 24/4/2022 7:22:22 AM
 * This controller handles project management.
 */
class Content_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('content_categories_model');
       
    }

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

    public function create()
    {
 $data = $this->content_categories_model->get_where_content_categories('0');
            $this->load->view('back_end_template/content', ['template' => 'backend/content_categories/create','data' => $data  ]);
        
      }
    public function add()
    {
       
       
        
            $data = $this->content_categories_model->create_content_categories([
            'id' => $this->input->post('id'),
            'name' => $this->input->post('name'),
            'slug' => $this->input->post('slug'),
            '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 content_categories has been created');
                return header('location: ' .base_url().'backend/content_categories/show/'.$data->id);
            }
        
    }

     public function search(){
        $data['template'] = 'backend/content_categories/index';
        $keyword = $this->input->post('keyword');   
        $column = $this->input->post('column');   
        $list_col = array('id' => $keyword,'name' => $keyword,'slug' => $keyword,'created_at' => $keyword,'updated_at' => $keyword,'deleted_at' => $keyword,); 
        if($column!="")
        {
          $columns="content_categories.$column";
          $list_col =array($columns => $keyword);
         }
        $config['$keyword'] = $keyword;
        $config['$columnsearch'] = $column;  
        $config['base_url'] = site_url('backend/content_categories/search/');
        $config['total_rows'] = $this->get_model->atc_get_count_search('content_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/content_categories/">';
        $config['cur_tag_close'] = '</a>';
        $this->pagination->initialize($config);
        
        $data['data'] = $this->get_model->atc_get_search('content_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->content_categories_model->get_where_content_categories($id);
        if (!$data) {
            $this->denied_message();

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

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

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

          return  header('location: ' .base_url().'backend/content_categories');
        }
        if ($this->content_categories_model->delete_content_categories($id)) {
            $this->session->set_flashdata('flash_success', 'Your content_categories has been deleted');
        } else {
            $this->denied_message();
        }
         return   header('location: ' .base_url().'backend/content_categories');

    }

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

 

nguyen tran

Leave a Reply

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