3

我看到很多這個問題,但我無法解決這個問題。在codeigniter分頁404錯誤

我懷疑它沒有讀取正確的段,因爲我有重新路由配置和htaccess刪除索引頁。

代碼拋出404頁面。

這裏是我的模型:

public function get_city_reviews($city_id,$limit,$offset) { 

    $list = array(); 

    $this->db->from('biz'); 

    $this->db->where('city_id',$city_id); 

    $this->db->order_by('created_at','desc'); 

    $this->db->limit($limit,$offset); 

    $query = $this->db->get(); 
    foreach($query->result() as $row) { 

    $list[] = $row; 

     } 

    return $list; 

    } 

我的控制器:

  $slug = $this->uri->segment(1,''); 
    if($slug) 
    { 
     $this->load->model('catsAndCities','cc'); 
     $this->cc->set_table_name('city'); 
     $city = $this->cc->get($slug,'slug'); 

     if(!$city || $city->parent_id != 0) 
     { 
      show_404(); 
     } 
     else 
     { 
      $this->tank_auth->set_user_city($city); 
     } 
    } 
    else 
    { 
     $city = $this->tank_auth->get_user_city(); 
    } 
    $this->load->library('pagination'); 

    $config = array(); 

    $base_url ="local/index/"; 

    $config["base_url"] = site_url().$base_url; 

    $config["total_rows"] = $this->bizs->record_count(); 

    $config["per_page"] = 5; 

    $config["uri_segment"] = 4; 

    $config['full_tag_open'] = '<p class="pageBar">'; 

    $config['full_tag_close'] = '</p>'; 

    $config['num_links'] =2; 

    $config['anchor_class'] = 'class="page-num" '; 

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

    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; 

    $data["results"] = $this->bizs->get_city_reviews($city->id,$config["per_page"], 
    $page); 

    $data["pagination_links"] = $this->pagination->create_links(); 

    $data['reviews'] = $data["results"]; 

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

筆者認爲:

<div id="pagination-container"> 
<div class="pagination"> 
    <ul> 

     <?=$pagination_links?> 

    </ul> 
    </div> 

這是我的路線:

$route['default_controller'] = "local/city"; 
    $route['[0-9a-zA-Z\-_]+'] = "local/city"; 
    $route['scaffolding_trigger'] = ""; 

這是我的htaccess:

<IfModule mod_rewrite.c> 
RewriteEngine On 

#Removes access to the system folder by users. 
#Additionally this will allow you to create a System.php controller, 
#previously this would not have been possible. 
#'system' can be replaced if you have renamed your system folder. 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php/$1 [L] 

#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn't true it sends the 
#request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 


ErrorDocument 404 /index.php 
</IfModule> 

回答

1

正如我懷疑,你告訴CI找到如果找不到城市,則爲404頁。嘗試對此進行評論:或者找到一種解決方法。

 if(!$city || $city->parent_id != 0) 
    { 
     show_404(); 
    } 
    else 
    { 
     $this->tank_auth->set_user_city($city); 
    } 

然後改變

$base_url ="local/index/"; 

$base_url =""; 

而且你的段1

$config["uri_segment"] = 1; 

應該這樣做。

+0

我沒有看到有人來,工作很好。 –

0

嘗試改變BASE_URL爲 「本地/城市」,並uri_segment改爲3

+0

@Winterrain這是一回事。 404頁。 –

+0

其實,哪個網址正在拋出404?默認頁面1是否工作,或者您只是獲得了頁面2,3等404。 – Winterain

+0

第一頁的作品,我得到了我想要的限制,但剩下的就是404. –