I am still learning with the CodeIgniter framework. Today, I find myself faced with the problem of pagination.
Indeed I would have access to data via an id which requires a variable in the url and another one for the pagination.
This is my foos_by_day function (this is not the real name, it's just an example) in my controller called foo that returns an array of foos on a specific day. These foos come from my database and go to my controller get_foos_by_day ($day) via the model called model_foos.
function foos_by_day($day) {
$configpages['base_url'] = 'http://www.exemple.com/ci/index.php/foo/foos_by_days/'.$foo."/";
$configpages['total_rows'] = count($this->model_foos->get_foos_by_day($foo));
$configpages['per_page'] = 10;
$config['uri_segment'] = 4;
$this->pagination->initialize($configpages);
$data['foos'] = $this->model_foos->get_foos_by_day($jour, (int)$this->uri->segment(4), $configpages['per_page'] );
$this->load->view('foo_view.php', $data);
}
And this is my view:
<?php foreach ($foos as $element): ?>
<div>
Name of the foo : <?=$element->name?><br />
Date of the foo : <?=$element->date?><br />
</div>
<?php endforeach; ?>
<?php echo $this->pagination->create_links(); ?>
I get something strange in my view when I input : http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/
The numbering of my 32 foos starts at 4 (the last page). It displays correctly 10 foos per pages but when I click on another page, the selected page stays the fourth. Moreover, the links behind the page numbers gives me the following statement:
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/">First</a>
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/20"><</a>
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/10">2</a>
<a href="http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/20">3</a>
<strong>4</strong>
So : nothing, then 20, 10 and 20 (again). In short there is a bug in the pagination.
Have you ever been faced to this kind of situation (with a pagination error)? If so, how did you solve it? How do you think I should proceed to find a regular pagination?
Thanks in advance.
P.S. : I didn't delete the index.php file but I have learned to do it on an other CodeIgniter.