代码之家  ›  专栏  ›  技术社区  ›  Sagar Parikh

代码点火器中未显示分页

  •  1
  • Sagar Parikh  · 技术社区  · 6 年前

    我正在开发CodeIgniter项目,但视图文件中没有显示分页。 我自动加载分页库 我在一个数据库中总共有7行,& per_page 设置5行。我也检查 print_r($config) &它能很好地显示数据。

    这是我的控制器:

    public function cust_list()
    {
        $this->load->model('Cus_model');
        $config =
        [
            'base_url'=>base_url('index.php/Cus_controller/cust_list'),
            'per_page'=>5,
            'totle_rows'=>$this->Cus_model->num_rows(),    
        ];
        $this->pagination->initialize($config);
        $customer=$this->Cus_model->customer_list($config['per_page'],$this->uri->segment(4));
        $this->load->view('salonadmin/customerview',['customers'=>$customer]);
     }
    

    这是我的 Cus_model 以下内容:

      public function customer_list($limit,$offset)
      {
      $user_id=$this->session->userdata('user_id');
      $query=$this->db
      ->select('*')
      ->from('customer')
      ->limit( $limit,$offset )
      ->get();
      return $query->result();
      }
      public function num_rows()
      {
      $user_id=$this->session->userdata('user_id');
      $query=$this->db
      ->select('*')
      ->from('customer')
    
      ->get();
    
      return $query->num_rows();
    
      }
    

    &这是我的观点:

    <?= $this->pagination->create_links();?>
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Nikesh barod    6 年前

    控制器

     public function cust_list() {
       $this->load->model('cus_model');
       $config["base_url"] = base_url() . "cus_controller/cust_list/";
       $config["total_rows"] = $this->cus_model->num_rows();
       $config["per_page"] = 5;
       $config['cur_tag_open'] = '&nbsp;<a class="current">';
       $config['cur_tag_close'] = '</a>';
       $config['next_link'] = 'Next';
       $config['prev_link'] = 'Previous';
       $this->pagination->initialize($config);
    
       // You should change your parameter according your url segment like 3 / 4
       if($this->uri->segment(3)){
          $page = $this->uri->segment(3);
       }else{ 
          $page = 0; 
       }
    
       $this->data["customers"] = $this->cus_model- 
       >customer_list($config["per_page"], $page);
       $str_links = $this->pagination->create_links();
       $this->data["links"] = explode('&nbsp;',$str_links );
    
       $this->load->view('salonadmin/customerview',$this->data);
    }
    

    模型

    public function customer_list($limit,$offset){
      $query = $this->db->select('*')->from('customer')->limit( $limit,$offset 
      )->get()->result();
      return $query;
    }
    
    public function num_rows()
    {
      $query = $this->db->select('*')->from('customer')->get()->num_rows();
      return $query;
    }
    

    视图

    <-- Pagination Link -->
    <ul class="pagination pull-right">
      <?php foreach ($links as $link) {
        echo "<li>". $link."</li>";
      } ?>
    </ul>