3

Я вижу много этого вопроса, но я не мог решить проблему.404 ошибка в codeigniter pagination

Я подозреваю, что он не читает правый сегмент, так как у меня есть конфигурация перенаправления и 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

Собственно, какой URL-адрес выбрасывает 404? Работает ли страница по умолчанию 1, или вы получаете только 404 с page2,3 и т. Д. – Winterain

+0

Работа на первой странице, я получаю ограничение, которое я хотел, но остальное бросить 404. –

Смежные вопросы