2017-10-09 24 views
1

Codeigniterとページネゴシエーションにいくつか問題があります。問題は、すべてのページですべての結果/投稿を取得できることです。Codeigniter - ページネーションが機能しない

Codeigniterとページネゴシエーションにいくつか問題があります。問題は、すべてのページですべての結果/投稿を取得できることです。

public function __construct() 
{ 
    parent::__construct(); 

    $this->load->model('SS_shilpi_model'); 
    $this->load->library('form_validation'); 
    $this->load->library('pagination'); 
} 

public function category(){ 
    $cid = $this->input->post('cid'); 
    if(isset($_GET['cid'])) 
    { 
     $cid = $_GET['cid']; 
     $this->SS_shilpi_model->catr3($cid); 
     $this->SS_shilpi_model->catr3_nr($cid); 
    } 

    $config = [ 
     'base_url' => base_url('category/?cid='. $cid .' '), 
     'per_page' => 12, 
     'total_rows' => $this->SS_shilpi_model->catr3_nr($cid), 
    ]; 

    $config['full_tag_open'] = '<ul style="overflow: hidden;" class="pagination">'; 
    $config['full_tag_close'] = '</ul>'; 
    $config['num_tag_open'] = '<li class="page-item">'; 
    $config['num_tag_close'] = '</li>'; 
    $config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">'; 
    $config['cur_tag_close'] = '</a></li>'; 
    $config['next_tag_open'] = '<li class="page-item">'; 
    $config['next_tagl_close'] = '</a></li>'; 
    $config['prev_tag_open'] = '<li class="page-item">'; 
    $config['prev_tagl_close'] = '</li>'; 
    $config['first_link'] = 'First <i class="fa fa-caret-left fa-2x push-left-5 pull-right green-text"></i>'; 
    $config['first_tag_open'] = '<li class="page-item disabled">'; 
    $config['first_tagl_close'] = '</li>'; 
    $config['last_link'] = '<i class="fa fa-caret-right fa-2x push-left-5 pull-right green-text"></i> Last'; 
    $config['last_tag_open'] = '<li class="page-item">'; 
    $config['last_tagl_close'] = '</a></li>'; 
    $config['attributes'] = array('class' => 'page-link'); 
    $this->pagination->initialize($config); // model function 

    $data['catr3d'] = $this->SS_shilpi_model->catr3($cid, $config['per_page'], $this->uri->segment(3)); // list of Category Details 
    // end pagination 

    $this->load->view('shilpi/category',$data); 
} 

私のモデルのコード:

public function catr3($cid){ 
    $this->db->select(''); 
    $this->db->order_by('id', 'DESC'); 
    $this->db->where('category_id',$cid); 
    $query = $this->db->get('all_posts'); 
    return $query->result(); 
} 

public function catr3_nr($cid){ 
    $this->db->select(''); 
    $this->db->order_by('id', 'DESC'); 
    $this->db->where('category_id',$cid); 
    $query = $this->db->get('all_posts'); 
    return $query->num_rows(); 

} 

マイビューコード:

<div id="catdata" class="col-xs-12 no-pull push-up-5 push-down-5 briefs"> 

       <?php 
        $count =1; 
        foreach($catr3d as $r) 
        { 

        if($count%4 == 1) 
        { 
          echo '<div class="col-xs-12 no-pull push-down-5">'; 

        } 

        ?> 

       <div class="col-sm-3 col-xs-12 no-pull-left pull-right-5"> 
        <div class="brief whitish-bg pull-5"> 
         <p class="red-text no-push"> 
          <?php echo $r->short_title; ?> 
         </p> 
         <a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>"> 
          <h5 class="blue-text font17 push-up-5"> 
           <?php echo $r->title; ?> 
          </h5> 
         </a> 
         <p> 
          <a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>"> 
           <img src="<?php echo base_url(); ?>upload/images/<?php echo $r->photo;?>" height="75" width="100" class="pull-left push-right-5 push-up-5"></img> 
          </a> 
          <?php 
         $string = $r->news; 
         $string = strip_tags($string); 

         if (strlen($string) > 500) { 


          $pos=strpos($string, ' ', 900); 
          $stringCut=substr($string,0,$pos); 
          echo $stringCut; 
         } 
          else { 
          echo $string; 
          } 

         ?> 
          <a href="<?php echo base_url(); ?>details/?pid=<?php echo $r->id; ?>"><i class="fa fa-caret-right fa-2x push-left-5 pull-right green-text"></i></a> 
         </p> 
        </div> 
       </div> 
       <?php 
       if ($count%4 == 0) 
        { 
         echo "</div>"; 
        } 
        $count++; 
       ?> 
       <div class="clear: both"></div> 
       <?php 
       } 
       if ($count%4 != 1) echo "</div>"; 
       ?> 

       <?= $this->pagination->create_links() ?> 

     </div> 
+0

試しを機能get_postsをモデル化するために、次のこのhttps://www.sitepoint.com/pagination-with-codeigniter/あなたが設定でいくつかのルートを設定する必要があるかもしれません注意/ route.phpます。http: //www.codeigniter.com/user_guide/general/routing.html#examples – user4419336

答えて

0

モデル関数にコントローラーの開始とリミットにこれを追加します。ここ

は私のコントローラコードがあります引数

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
    $data['posts'] = $this->post->get_posts($config["per_page"], $page); 

そして

$this->db->limit($limit, $start); 
関連する問題