2017-02-01 2 views
1

Я не понимаю, почему это происходит, но та же самая строка на каждой странице перезагрузки показывает. Я новичок в Codeigniter и знаю основы php и программирования. Благодарим вас за помощь заранее.codeigniter 3.1.3 pagination показывает ту же запись

Модель:

class Clanovi_model extends CI_Model { 
    public function __construct() { 
     $this->load->database(); 
    } 

    public function get_clanovi($limit, $offset) { 
     $this->db->limit($limit, $offset); 
     $query = $this->db->get('clan'); 

     return $query->result(); 
    } 

    public function broji_clanove() { 
     return $this->db->count_all('clan'); 
    } 
} 

Контроллер:

class Clanovi extends CI_Controller { 

    public function index() { 

     $this->load->model('Clanovi_model'); 
     $this->load->library('pagination'); 
     $this->load->helper('url'); 

     $config['base_url'] = 'http://localhost/codeigniter5/index.php/clanovi'; 
     $config['total_rows'] = $this->Clanovi_model->broji_clanove(); 
     $config['per_page'] = 1; 

     $this->pagination->initialize($config); 
     $data['clanovi'] = $this->Clanovi_model->get_clanovi($config['per_page'], $this->uri->segment(3)); 
     $data['paginacija'] = $this->pagination->create_links(); 

     $this->load->view('zaglavlje'); 
     $this->load->view('clanovi', $data); 
     $this->load->view('podnozje'); 
    } 
} 

вид:

<h2>Članovi</h2> 
<hr> 
<table class="table table-striped"> 
<tr> 
<th>Ime</th> 
<th>Prezime</th> 
<th>Adresa</th> 
<th>Korisničko ime</th> 
<th>Lozinka</th> 
</tr> 
<?php foreach ($clanovi as $clan): ?> 

<tr> 
    <td><?php echo $clan->ime; ?></td> 
    <td><?php echo $clan->prezime; ?></td> 
    <td><?php echo $clan->adresa; ?></td> 
    <td><?php echo $clan->korisnicko_ime; ?></td> 
    <td><?php echo $clan->lozinka; ?></td> 
</tr> 

<?php endforeach; ?> 
</table> 

<?php echo $paginacija; ?> 

маршруты:

$route['clanovi/(:num)'] = 'clanovi/index/$1'; 
$route['clanovi'] = 'clanovi'; 

screenshot1 screenshot2

ответ

0

Нашли решение, посмотрев, что такое $ this-> uri-> segment (3); и изменено на 2.

$data['clanovi'] = $this->Clanovi_model->get_clanovi($config['per_page'], $this->uri->segment(2)); 
Смежные вопросы