2015-07-03 6 views
2

У меня есть эта функция в контроллере, который называют весь деталь от модели и сделать нумерацию страниц в домашней странице, поэтому я называю страницу как:Codeigniter: не будет работать пагинацию с CodeIgniter

http://localhost/cart/index.php/ 

Когда перейти к следующей странице покажите мне эту ошибку:

404 Page Not Found 

Мой контроллер: -

public function index() { 
    $config = array(); 
    $config["base_url"] = base_url() . "index.php"; 
    $config["total_rows"] = $this->main_model->record_count(); 
    $config["per_page"] = 8; 
    $config["uri_segment"] = 2; 

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

    $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0; 
    $data["home_products"] = $this->main_model->fetch_items($config["per_page"], $page); 
    $data["links"] = $this->pagination->create_links(); 
    $data['categories'] = $this->main_model->getAllCategories(); 

    $this->load->view("home", $data); 
} 

и модель:

public function record_count() { 
      return $this->db->count_all("wg_items"); 
    } 

    public function fetch_items($limit, $start) { 
     $this->db->limit($limit, $start); 
     $query = $this->db->get("wg_items"); 

     if ($query->num_rows() > 0) { 
      foreach ($query->result() as $row) { 
       $data[] = $row; 
      } 
      return $data; 
     } 
     return false; 
    } 

и вид:

 <!-- Show pagination links --> 
     <p style="float:left"><?php echo $links; ?></p> 

Где ошибка ??

ответ

0

В контроллере

$count = $this->main_model->record_count(); 

$config = array(); 
$config["base_url"] = base_url() .'index.php/Front/index'; 
$config["total_rows"] = $count ; 
$config["per_page"] = 8; 
$config["uri_segment"] = 3; 
$limit = $config['per_page']; 

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

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

$data['home_products'] = $this->main_model->get_item($page,$limit); 

в модели

public function get_item($page,$limit) 
{ 
    $query = $this->db->query("SELECT * FROM table name LIMIT $page, $limit");//your argument 
    $result = $query->result_array(); 
    return $result; 
} 

в config/config.php

$config['base_url'] = ''; 
$config['index_page'] = ''; 

в .htaccess (место за пределами applicatino папки)

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

thankx, но показывает мне ошибку '' Сообщение: Попытка получить свойство не-объекта –

+0

вы можете загрузить полный код. il сделать это правильно. пост, модель и контроллер. –

+0

как вы получаете товар? передавая любой 'id' через url ?? –

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