2017-10-31 8 views
0

私はしばらくこの問題を解決するために取り組んできましたが、うまくいきません。 2ページ目に404エラーが表示されます。もし誰かがコードを見直す時間を見つけたら、感謝します。私もルートで作業しましたが、それでも2ページに404エラーが表示されます。ここ は コントローラCodeigniter:ページネーション、2ページが見つかりません

public function __construct() 
    { 
     parent::__construct(); 
     $this->load->model('Products_model'); 
     $this->load->helper('form'); 
     $this->load->library('pagination'); 
    } 

public function index($offset = 0) { 
     //how many blogs will be shown in a page 
     $limit = 3; 
     $result = $this->Products_model->get_blogs($limit, $offset); 
     $data['blog_list'] = $result['rows']; 
     $data['num_results'] = $result['num_rows']; 
     // load pagination library 
     $config = array(); 
     $config['base_url'] = 'http://localhost/nwpgroup/nwp2/index.php'; 
     $config['total_rows'] = $data['num_results']; 
     $config['per_page'] = $limit; 
     //which uri segment indicates pagination number 
     $config['uri_segment'] = 3; 
     $config['use_page_numbers'] = TRUE; 
     //max links on a page will be shown 
     $config['num_links'] = 5; 
     //various pagination configuration 
     $config['full_tag_open'] = '<div class="pagination">'; 
     $config['full_tag_close'] = '</div>'; 
     $config['first_tag_open'] = '<span class="first">'; 
     $config['first_tag_close'] = '</span>'; 
     $config['first_link'] = ''; 
     $config['last_tag_open'] = '<span class="last">'; 
     $config['last_tag_close'] = '</span>'; 
     $config['last_link'] = ''; 
     $config['prev_tag_open'] = '<span class="prev">'; 
     $config['prev_tag_close'] = '</span>'; 
     $config['prev_link'] = ''; 
     $config['next_tag_open'] = '<span class="next">'; 
     $config['next_tag_close'] = '</span>'; 
     $config['next_link'] = ''; 
     $config['cur_tag_open'] = '<span class="current">'; 
     $config['cur_tag_close'] = '</span>'; 
     $this->pagination->initialize($config); 
     $data['pagination'] = $this->pagination->create_links(); 
     $this->load->view('products', $data); 
    } 

モデルの一部

public $products = 'products'; 


    public function get_blogs($limit, $offset) { 
      if ($offset > 0) { 
       $offset = ($offset - 1) * $limit; 
      } 
      $result['rows'] = $this->db->get($this->products, $limit, $offset); 
      $result['num_rows'] = $this->db->count_all_results($this->products); 
      return $result; 
     } 

ビューです。

<?php 
     foreach ($blog_list->result() as $blog) { 
      ?> 
      <div class="post"> 
       <h2 class="title"><?php echo $blog->id; ?></h2> 
       <p class="meta"> 
        <?php 
        echo $blog->name; 
        ?> 
       <div class="entry"> 
        <p><?php echo $blog->price; ?></p> 
       </div> 
      </div> 
     <?php 
     } 
     if (strlen($pagination)) { 
      echo $pagination; 
     } 
    ?> 

このコードを確認していただきありがとうございます。

+0

フルコントローラーを表示 –

+0

@ B.Desai、コントローラーを更新しました –

+0

コントローラー名は何ですか? –

答えて

2

あなたは、データがモデルからフェッチされたあなたのコントローラ機能を指しているページネーションに

$config['base_url'] = 'http://localhost/nwpgroup/nwp2/index.php/products/index/'; 
+0

ありがとうございます、それは働いています! –

0

ベースURLに改ページ

変更

$config['base_url'] = 'http://localhost/nwpgroup/nwp2/index.php'; 

ためbase_urlに問題があります。

はあなたがindex.phpと、プロジェクトのURLを返します

$config['base_url'] = site_url("products/index/"); 

site_urlとしてBASE_URL設定する必要があります。

+0

ありがとう@kumar_v –

関連する問題