CodeIgniter分页问题 [英] CodeIgniter Pagination Problem
问题描述
我使用codeigniter和它的分页类。它工作完美,它看起来像这样:
I am using codeigniter and its pagination class. It works perfectly and it looks something like this:
«第一& 1 2 3 4 5>最后»
« First < 1 2 3 4 5 > Last »
这是我的代码:
$this->load->library('pagination');
$config['base_url'] = base_url().'controlpanel/';
$config['first_link'] = 'First';
$config['total_rows'] = $count;
$config['per_page'] = '3';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('controlpanel', $data);
我在我的路线中有这个:
I have this in my routes:
$route['controlpanel/(:num)'] = "controlpanel/index/$1";
但是,每当我到达一个不同的页面 controlpanel / 3
- 数字1总是粗体 - 它应该更改为2或3等!
However, whenever I get to a differentpage i.e. controlpanel/3
- the number 1 is always bold - it should change to 2 or 3 etc!
为什么不是?
当我改变 $ config [ base_url'] 到
base_url()。'controlpanel / page'
然后通过加粗正确的数字正确地工作 - 到 controlpanel / page
这是错误的页面,因为基础只是 controlpanel
。
When I change the $config['base_url']
to base_url().'controlpanel/page'
then does the pagination work correctly by boldening the correct number - but the link 1 points to the URL controlpanel/page
which is the wrong page for me as the base is just controlpanel
.
感谢所有人的帮助。
推荐答案
分页类应检查第二个参数,而不是第三个(默认)。
The pagination class should check the second parameter, not the third(default).
将此添加到配置数组中以更改:
Add this to the config array to change this:
$config['uri_segment'] = '2';
这不会改变任何东西,创建所需的url。
改变这个:
This won't change anything but be helpful in creating the url needed. change this :
$config['base_url'] = base_url().'controlpanel/';
:
$config['base_url'] = site_url('controlpanel');
这篇关于CodeIgniter分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!