CodeIgniter 上的 url 中有 2 个变量时出现分页错误
我仍在学习 CodeIgniter 框架。今天,我发现自己面临着分页的问题。
事实上,我可以通过 id 访问数据,这需要 url 中的一个变量和另一个用于分页的变量。
这是我的控制器中名为 foo 的 foos_by_day 函数(这不是真实名称,这只是一个示例),它返回特定日期的 foos 数组。 这些 foo 来自我的数据库,并通过名为 model_foos 的模型转到我的控制器 get_foos_by_day ($day)。
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);
}
这是我的观点:
<?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(); ?>
当我输入时,我的观点有些奇怪: http://www.example.com/ci/index.php/foo/foos_by_day/2011-09-28/
我的 32 个 foo 的编号从 4 开始(最后一页)。它每页正确显示 10 foos,但当我单击另一个页面时,所选页面仍保持在第四个。 此外,页码后面的链接给出了以下声明:
<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>
所以:什么都没有,然后是 20、10 和 20(再次)。总之分页有bug。
您是否遇到过这种情况(分页错误)?如果是这样,你是如何解决的? 您认为我应该如何找到常规分页?
提前致谢。
PS:我没有删除index.php 文件,但我已经学会在其他CodeIgniter 上执行此操作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改变
$config['uri_segment'] = 4;
到
$configpages['uri_segment'] = 4;
Change
$config['uri_segment'] = 4;
to
$configpages['uri_segment'] = 4;