Welcome Guest, Not a member yet? Register   Sign In
Pagination doesn't work :s
#1

[eluser]Unknown[/eluser]
Hi guys,
I'm trying to use the pagination library for my website but I have some problems with it.

Here is my controller code:
Code:
class Projets extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->model('projets_model', 'projetsManager');
}

public function liste()
{
  $this->load->library('pagination');

  $per_page = 10;
  $total_rows = $this->projetsManager->projets_count();
  $offset = $this->uri->segment(3);
    
  $config['base_url'] = site_url('/projets/liste/');
  $config['total_rows'] = $total_rows;
  $config['per_page'] = $per_page;
  
  $data['categories'] = $this->projetsManager->get_categories();
  $data['pagination'] = $this->pagination->create_links();
  $data['projets'] = $this->projetsManager->get_all_projets($per_page, $offset);
  
  $this->pagination->initialize($config);
  
  $this->load->view('site/projets_view', $data);
  
}
}
Here is my model code:
Code:
class Projets_model extends CI_Model
{
protected $table = 'projets';

        public function projets_count()
{
  return $this->db->count_all($this->table);
}

public function get_all_projets($limit, $offset)
{
  $query = $this->db->get($this->table, $limit, $offset);
  return $query->result();
}
}

And finaly my view code:
Code:
<?php foreach ($projets as $projet) {
echo $projet->title;
}
?>

<?php echo $pagination?>

So it well displays the 10 first projets title but then I have no pagination links.

Please help me I watched many tutorials and my code seems allright I don't understand what's wrong.
#2

[eluser]Flemming[/eluser]
At a glance your code looks OK so first thing to make sure of is that your total_rows contains a value more than 10

$total_rows = $this->projetsManager->projets_count();

you could try just assigning a static value to $total_rows, say 50:

$total_rows = 50;

and see if that causes pagination links to be displayed?
#3

[eluser]InsiteFX[/eluser]
Code:
liste($offset = '')
{
    $config['uri_segment'] = 3;
}
#4

[eluser]jairoh_[/eluser]
you should pass $offset like

Code:
public function liste( $offset )
{
          //codes here
}
w/ regards to your $config['base_url']




Theme © iAndrew 2016 - Forum software by © MyBB