簡體   English   中英

當我點擊分頁上的下一頁時,它會在 codeigniter 中出現 404 錯誤

[英]When I click to the next page on pagination,it goes to 404 error in codeigniter

在我的News.php控制器中,我有以下代碼:

 public function index()
{
    $data['title'] = 'Database Details';

    $config     =   array();
    $config['base_url'] =   base_url("news/index");
    $config['total_rows'] = $this->news_model->record_count();
    $config['per_page']     =   5;
    $config['uri_segment'] = 3;
    //$config['use_page_numbers'] = TRUE;
 // $config['page_query_string'] = TRUE;

    $choice  =  $config["total_rows"] / $config["per_page"];
    $config["num_links"] =  round($choice);

     $this->pagination->initialize($config);

    $page   = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    //echo "page--".$page;
    $data['user_data']  = $this->news_model->get_details($config['per_page'],$page);
    $data['links']          =  $this->pagination->create_links();

    $this->load->view('templates/header');   
    echo $this->db->last_query();       

    $this->load->view('news/index', $data);   

    $this->load->view('templates/footer');
}

在我的News_Model.php模型中,存在以下代碼:

 public function get_details($limit,$start)
{    
    //echo "Limit---".$limit."</br>";
    //echo "Start---".$start."</br>";
      $this->db->limit($limit,$start);
      $query = $this->db->get('user_data'); 
      return $query->result_array();    

 }

我的視圖文件index.php顯示:

 <h3>
   <?php echo $title; ?>
 </h3>
 <table>
    <thead>
      <th>Name</th>
      <th>Address</th>
      <th>Email</th>
       <th>Mobile</th>
    </thead>
   <tbody>
   <?php
       //print_r($user_data);
     foreach ($user_data as $user_item): 
   ?>
   <tr>

      <td><?php echo $user_item["user_name"];?></td>
     <td><?php echo $user_item["address"];?></td>
     <td><?php echo $user_item["email"];?></td>
     <td><?php echo $user_item["mobile"];?></td>
     <td><a href="edit?id=<?php echo $user_item["id"];?>">Edit</a></td>
     <td><a href="delete?id=<?php echo $user_item["id"];?>">Delete</a></td>
   </tr>
<?php endforeach ?>

 </tbody>
 </table>
 <p class="pagination"><?php echo $links; ?></p>

在我的config.php

 <?php
      $config['base_url'] = 'http://localhost/CodeIgniter-3.0.0/';
      $config['index_page'] = 'index.php';
 ?>

如果我刪除 $config['index_page'] = ''; 我的其他頁面不顯示。

在我的route.php

  <?php
    $route['news/(:any)'] = 'news/index/$1'; //explain what does it actually means?
    $route['news'] = 'news';
    $route['default_controller'] = 'news/create';
    $route['(:any)'] ='pages/view/$1';

 ?>

上面的代碼顯示如下:

在此處輸入圖片說明

但是當我點擊page 2它顯示為:在此處輸入圖片說明

請不要建議Link1Link2Link3 。我已經看到了上面的鏈接,但不知道如何獲得它:(

請指導我!!

在 config.php

$config['base_url'] = 'https://stackoverflow.com/';
$config['index_page'] = '';

在您的路由器中

$route['news/(:any)'] = 'news/$1';
$route['news'] = 'news';
$route['default_controller'] = 'news/create';
$route['(:any)'] ='pages/view/$1';

並放置 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

編輯 01

<?php

    $data['title'] = 'Database Details';

    $count = $this->news_model->record_count()

    $config['base_url'] =   base_url(). 'index.php/news/index';
    $config['total_rows'] = $count;
    $config['per_page']     =   5;
    $config['uri_segment'] = 3;
    $limit = $config['per_page'];

     $this->pagination->initialize($config);

    $page   = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['user_data']  = $this->news_model->get_details($limit,$page);
    $data['links']    =  $this->pagination->create_links();


    $this->load->view('templates/header');   
    $this->load->view('news/index', $data);   
    $this->load->view('templates/footer');

刪除$config['use_page_numbers'] = TRUE; 然后檢查。

還有為什么你有 2 條路線:

$route['news/(:any)'] = 'news/index/$1'; //explain what does it actually means?
$route['news'] = 'news';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM