Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中的分页-第二页_Php_Codeigniter - Fatal编程技术网

Php codeigniter中的分页-第二页

Php codeigniter中的分页-第二页,php,codeigniter,Php,Codeigniter,我试图在codeigniter中进行分页。它在第一页中运行良好。但当我点击第二页时,页面似乎是空白的。数据未加载 我的控制器: <?php class Generate_report extends CI_Controller { public $newdata; public $layout = 'default'; public $html = ''; public $title = 'Title'; function __construct

我试图在codeigniter中进行分页。它在第一页中运行良好。但当我点击第二页时,页面似乎是空白的。数据未加载

我的控制器:

<?php
class Generate_report extends CI_Controller {

    public $newdata;
    public $layout = 'default';
    public $html = '';
    public $title = 'Title';

    function __construct() {
        parent::__construct();
        if ($this->router->method == 'index') {
            $this->config->set_item('enable_hooks', FALSE);
        }

        $this->load->helper('form');
        $this->load->helper(array('url', 'left_menu'));
         $this->load->library('pagination');
        $this->load->library(array('form_validation', 'session'));
        $this->load->model('getReportModel');
        $this->left_menu = display_menu($this->session->userdata('role'));
    }
       public function generate_employeereport($offSet = NULL){

        //$this->config->set_item('enable_hooks', FALSE);
            if ($this->session->userdata('role') == "Admin" ||$this->session->userdata('role') == "HR Manager") {

               if(isset($_GET['submit'])) { 

                $session_data = $this->session->all_userdata();
                $category = $this->input->get('category');
                $report_join_date = date("Y-m-d", strtotime($this->input->get('report_join_date')));
                $designation = $this->input->get('designation');
                $purpose = $this->input->get('purpose');
                $data['category']= $category;
                $data['report_join_date']= $this->input->get('report_join_date');
                $data['designation']= $designation;

                $where= array();
                if($category == "Less than"){
                if($report_join_date!="")
                {
                 $where+= array("primary_details.date_join <" => $report_join_date);   
                }
                }
                else if($category == "Less than or Equal to"){
                if($report_join_date!="")
                {
                 $where+= array("primary_details.date_join <=" => $report_join_date);   
                }
                }
                else if($category == "Greater than"){
                if($report_join_date!="")
                {
                 $where+= array("primary_details.date_join >" => $report_join_date);   
                }
                }
                else if($category == "Greater than or Equal to"){
                if($report_join_date!="")
                {
                 $where+= array("primary_details.date_join >=" => $report_join_date);   
                }
                }
                else {
                if($report_join_date!="")
                {
                 $where+= array("primary_details.date_join" => $report_join_date);   
                }
                }
                if($designation!="")
                {
                 $where+= array("ta_designations.designations" => $designation);   
                }
              $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
              $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
              $config["per_page"] = 50;
              $config["uri_segment"] = 3; //part of the URL which contain the page section
              $config['use_page_numbers'] = FALSE;
              $config['reuse_query_string']=TRUE;
              $config['full_tag_open'] = '<ul>';
              $config['full_tag_close'] = '</ul>';
              $config['num_tag_open'] = '<li>';
              $config['num_tag_close'] = '</li>';
              $config['cur_tag_open'] = '<li><a class="current" href="#">';
              $config['cur_tag_close'] = '</a></li>';
              $config['prev_tag_open'] = '<li>';
              $config['prev_tag_close'] = '</li>';
              $config['prev_link'] = '←';
              $config['next_link'] = '→';
              $config['next_tag_open'] = '<li>';
              $config['next_tag_close'] = '</li>';
              $config['first_link'] = 'First';
              $config['first_tag_open'] = '<li>';
              $config['first_tag_close'] = '</li>';
              $config['last_link'] = 'Last';
              $config['last_tag_open'] = '<li>';
              $config['last_tag_close'] = '</li>';
              $data['offSet'] = $offSet;
              $this->pagination->initialize($config);
              $data['employees'] = $this->getReportModel->getEmployees($where, $config["per_page"], $offSet);
              $this->html= $this->load->view('report_generation/employee_report',$data,TRUE);  
            }  
        }
}

  • 加入日期 挑选 试试这个

    在控制器中

    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config["uri_segment"] = 2; # Changed
    $limit = $config['per_page']; # added
    
    <!-- Rest of your code -->
    
    //$data['offSet'] = $offSet; remove this
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0; # added
    
    
    $data['employees'] = $this->getReportModel->getEmployees($where, $page, $limit);
    $this->html= $this->load->view('report_generation/employee_report',$data,TRUE);  
    
    $this->load->library('pagination'); 
    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config['page_query_string'] = TRUE;
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
    $data['employees'] = $this->getReportModel->getEmployees($where, $config["per_page"]); # Here passed only two parameters
    
    试试这个

    在控制器中

    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config["uri_segment"] = 2; # Changed
    $limit = $config['per_page']; # added
    
    <!-- Rest of your code -->
    
    //$data['offSet'] = $offSet; remove this
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0; # added
    
    
    $data['employees'] = $this->getReportModel->getEmployees($where, $page, $limit);
    $this->html= $this->load->view('report_generation/employee_report',$data,TRUE);  
    
    $this->load->library('pagination'); 
    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config['page_query_string'] = TRUE;
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
    $data['employees'] = $this->getReportModel->getEmployees($where, $config["per_page"]); # Here passed only two parameters
    

    控制器上启用
    $config['page\u query\u string']

    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config["uri_segment"] = 2; # Changed
    $limit = $config['per_page']; # added
    
    <!-- Rest of your code -->
    
    //$data['offSet'] = $offSet; remove this
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0; # added
    
    
    $data['employees'] = $this->getReportModel->getEmployees($where, $page, $limit);
    $this->html= $this->load->view('report_generation/employee_report',$data,TRUE);  
    
    $this->load->library('pagination'); 
    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config['page_query_string'] = TRUE;
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
    $data['employees'] = $this->getReportModel->getEmployees($where, $config["per_page"]); # Here passed only two parameters
    
    在您的模型上使用以下命令更改查询-

    public function getEmployees($where,$limit) {
    
            $offSet=$this->input->get('per_page');
            if(!$offSet){
    
                $offSet=0;
            }
          $result ="";
    
          $this->db->select('primary_details.name,primary_details.date_birth,primary_details.date_join,ta_designations.designations');
          $this->db->from('primary_details');
          $this->db->join('ta_designations', 'primary_details.designation =  ta_designations.id');
          $this->db->join('joining_details', 'primary_details.p_id =  joining_details.empl_id');
          $this->db->where('joining_details.active', 1);
          if($where!=""){     
    
          $this->db->where($where);
           }
          $this->db->limit($limit, $offSet);
    
          $query = $this->db->get();
          //echo $this->db->last_query();
          $result = $query->result_array();
          return $result;
        }   
    

    控制器上启用
    $config['page\u query\u string']

    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config["uri_segment"] = 2; # Changed
    $limit = $config['per_page']; # added
    
    <!-- Rest of your code -->
    
    //$data['offSet'] = $offSet; remove this
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0; # added
    
    
    $data['employees'] = $this->getReportModel->getEmployees($where, $page, $limit);
    $this->html= $this->load->view('report_generation/employee_report',$data,TRUE);  
    
    $this->load->library('pagination'); 
    $config["base_url"] = base_url() . "generate_report/generate_employeereport/";
    $config["total_rows"] = $this->getReportModel->getEmployees_count($where); 
    $config["per_page"] = 50;
    $config['page_query_string'] = TRUE;
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
    $data['employees'] = $this->getReportModel->getEmployees($where, $config["per_page"]); # Here passed only two parameters
    
    在您的模型上使用以下命令更改查询-

    public function getEmployees($where,$limit) {
    
            $offSet=$this->input->get('per_page');
            if(!$offSet){
    
                $offSet=0;
            }
          $result ="";
    
          $this->db->select('primary_details.name,primary_details.date_birth,primary_details.date_join,ta_designations.designations');
          $this->db->from('primary_details');
          $this->db->join('ta_designations', 'primary_details.designation =  ta_designations.id');
          $this->db->join('joining_details', 'primary_details.p_id =  joining_details.empl_id');
          $this->db->where('joining_details.active', 1);
          if($where!=""){     
    
          $this->db->where($where);
           }
          $this->db->limit($limit, $offSet);
    
          $query = $this->db->get();
          //echo $this->db->last_query();
          $result = $query->result_array();
          return $result;
        }   
    
    尝试添加
    $config[“num_links”]=10到分页
    config
    添加
    error\u报告(E\u ALL)
    并查看出现的错误。尝试添加
    $config[“num_links”]=10到分页
    config
    添加
    error\u报告(E\u ALL)并查看您得到的错误。。