我已将溃败设为
$route['dog/(:any)'] = "dog/index/$1"; /// for single dog info
$route['dog/list'] = "dog/listing"; /// for dog list, display all dogs.
$route['dog/list/(:num)'] = "dog/listing/$1"; /// for pagination
单狗网址就像dog / dogName-4.html
我的控制器是
public function index()
{
$dogInfo = $this->uri->segment(2);
if ($dogInfo != "")
{
$dogDetails = explode('-', $dogInfo);
$this->load->view('common/header',$header);
$this->load->view('dog/dog_info', $content);
$this->load->view('common/footer', $footer);
}
else
redirect('welcome', 'location', 301);
}
public function listing()
{
$this->load->library("pagination");
$breed = $this->input->get('breed');
$gender = $this->input->get('gender');
$state = $this->input->get('state');
$seller = $this->input->get('seller');
$config = array();
$config["base_url"] = base_url() . "dog/list/";
$config["total_rows"] = $this->dogs->get_dog_list_count($breed, $gender, $state, $seller);
$config["per_page"] = 5;
$config["uri_segment"] = 2;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$content['details'] = $this->dogs->get_dog_list($config["per_page"], $page,$breed, $gender, $state, $seller);
$content['paginatonLinks'] = $this->pagination->create_links();
$content['total_dogs'] = $config['total_rows'];
$content['cur_page'] = $page + 1;
$content['total_pages'] = ceil($config["total_rows"] / $config["per_page"]);
$this->load->view('common/header');
$this->load->view('dog/dog_list', $content);
$this->load->view('common/footer', $footer);
}
控制器的索引功能是显示一只狗的信息,列表功能适用于所有狗,
我必须为列表功能设置分页我确实为分页设置了所有必需的变量,分页显示结果
找到[134]广告::第1页,共27页1 2 3>最后>
但是当我点击页面上的分页1 2 3时,它会将我带到索引页面。
我需要在控制器的列表功能上。请任何人帮助我。
这是更新的代码
溃败码是
$route['dog/list'] = "dog/listing";
$route['dog/list/(:num)'] = "dog/listing/$1";
$route['dog/(:any)'] = "dog/index/$1";
这是更新的控制器代码
$config = array();
$config["base_url"] = base_url() . "dog/list/";
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config["total_rows"] = $this->dogs->get_dog_list_count($breed, $gender, $state, $seller);
$config["uri_segment"] = 3;
$config["per_page"] = 5;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['cur_tag_open'] = '<a href="#" class="page_selected">';
$config['cur_tag_close'] = '</a>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$this->load->model('DogsListing_model', 'dogs');
$this->load->model('Breed_model', 'breeds');
$content['breeds'] = $this->breeds->get_all_id_title();
$content['details'] = $this->dogs->get_dog_list($config["per_page"], $page,$breed, $gender, $state, $seller);
$content['search'] = array('breed' => $breed, 'gender' => $gender, 'state' => $state, 'seller' => $seller);
$content['paginatonLinks'] = $this->pagination->create_links();
$content['total_dogs'] = $config['total_rows'];
$content['cur_page'] = $page + 1;
$content['total_pages'] = ceil($config["total_rows"] / $config["per_page"]);
答案 0 :(得分:1)
我找到了问题的解决方案
首先我使用$this->uri->segment(3) and $config["uri_segment"] = 3;
我使用错误的uri-&gt;段进行分页。这解决了与分页有关的问题。
我的下一部分是我必须为卖家设置变量或使用分页设置搜索结果。例如,我有网址doglist.html/?seller=29
我需要嵌入这个分页的分页。所以结果就像dog/list/3?breed=&gender=female&state=&submit2=Fetch
我用这行代码$config['suffix'] = '?'.http_build_query($_GET, '', "&");
解决了这个问题,现在我对变量的分页工作正常。
感谢@jtheman和@Venkat,但主要是@jtheman的贡献。
答案 1 :(得分:0)
如果您对pagination有任何疑问,请查看我写的这个广义函数作为另一个问题的答案。