Welcome Guest, Not a member yet? Register   Sign In
Pagination bug?
#1

[eluser]Unknown[/eluser]
Hi there,

I'm using the pagination library for the first time and I'm wondering if I'm doing something wrong here.

This code:

Code:
$this->load->library('pagination');
$config_paginas['base_url'] = '/cms/blog/postlijst/';
$config_paginas['total_rows'] = 4;
$config_paginas['uri_segment'] = 4;
$config_paginas['per_page'] = 1;
      
$this->pagination->initialize($config_paginas);
echo $this->pagination->create_links();

Outputs these links:

1 = /cms/blog/postlijst/
2 = /cms/blog/postlijst/1
3 = /cms/blog/postlijst/2
4 = /cms/blog/postlijst/3

So page 1 is actually page 0, page 2 is page 1 etc. Before I used codeigniter I didn't do it this way, but if this is the way it works in CI it's fine by me.

But every time there are only 2 pages, for example in this code

Code:
$this->load->library('pagination');
      
$config_paginas['base_url'] = '/cms/blog/postlijst/';
$config_paginas['total_rows'] = 4;
$config_paginas['uri_segment'] = 4;
$config_paginas['per_page'] = 2;
                                                                                
$this->pagination->initialize($config_paginas);
echo $this->pagination->create_links();

It outputs these links:


1 = /cms/blog/postlijst/
2 = /cms/blog/postlijst/2

So suddenly page 2 is 2 instead of 1.

Am I doing something wrong here? Or is this a bug or is there a special reason why it works this way?

The problem is that I build a query based on the page querystring, but if this is the way it works I need to write extra code to let the script take care of lists with only 2 pages, and lists with more than 2 pages and this doesn't really seem necessary.

Thanks in advance! :lol:
#2

[eluser]osci[/eluser]
it isn't showing page number, it's showing record number (offset).
#3

[eluser]Unknown[/eluser]
Here is my pagination and it work fine.

class Clients extends MY_Controller
{
//=====================================================================================================================================================================================
// Variables
//=====================================================================================================================================================================================
private $limit = 8;
private $data = array();
//=====================================================================================================================================================================================
//=====================================================================================================================================================================================
// Fonction
//=====================================================================================================================================================================================
//=====================================================================================================================================================================================
function Clients()
{
parent::MY_Controller();
$this->load->library(array('table','form_validation'));
$this->load->helper('url');
$this->load->model('clients_model','',TRUE);
$this->load->model('utils_model','',TRUE);
}
//=====================================================================================================================================================================================
//=====================================================================================================================================================================================
// Fonction index
//=====================================================================================================================================================================================
//=====================================================================================================================================================================================
function index($offset = 0)
{
$this->data['meta_titre']= $this->lang->line('METATAG_TITLE_LISTE_CLIENTS');
$this->data['meta_description']= $this->lang->line('METATAG_DESCRIPTION_LISTE_CLIENTS');
$this->data['titre'] = 'Liste des Clients';
$this->data['pagination']=$this->set_pagination();
$clients = $this->clients_model->get_liste($this->limit, $offset);
// generate table data
$this->load->library('table');
$this->table->set_empty(" ");
$this->table->set_heading('No', 'Nom', 'Ville', 'Téléphone', 'Adresse Email', 'Actions');
$i = 0 + $offset;
if ($this->clients_model->get_nombre_enrg() > 0)
{
foreach ($clients as $client)
{
++$i;
$this->table->add_row( $client->id, $this->clients_model->get_full_name($client), $client->cs_code_postal.' '.$client->cs_ville,$client->cs_tel_fixe,$client->cs_email,
anchor('admin/clients/view/'.$client->id,'view',array('class'=>'view')).' '.
anchor('admin/clients/delete/'.$client->id,'delete',array('class'=>'delete','onclick'=>"return confirm('Etes vous sur de vouloir supprimer ce client?')"))
);
}
}
$this->data['table'] = $this->table->generate();
$this->data['bouton_nouveau'] = anchor('admin/clients/view/','Nouveau client',array('class'=>'bouton right margin_right_10'));
$this->load->view('admin/clients/clients_liste', $this->data);
}

function set_pagination()
{
$this->load->library('pagination');
$uri_segment = 4;
$offset = $this->uri->segment($uri_segment);
$config['uri_segment'] = $uri_segment;
$config['base_url'] = site_url('admin/clients/index/');
$config['total_rows']=$this->clients_model->get_nombre_enrg();
$config['per_page'] = $this->limit;
//$config['full_tag_open'] = '<li>';
//$config['full_tag_close'] = '</li>';
$this->pagination->initialize($config);
return $this->pagination->create_links();
}

and in my clients_model (database)
//=====================================================================================================================================================================================
//=====================================================================================================================================================================================
// Fonction
//=====================================================================================================================================================================================
//=====================================================================================================================================================================================
function get_liste($limit = 10, $offset = 0)
{
$this->db->order_by('id','asc');
$query = $this->db->get($this->db_table, $limit, $offset);
if($query->num_rows()>0)
{
return $query->result();
}
}




Theme © iAndrew 2016 - Forum software by © MyBB