1

我已将溃败设置为

$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 > 最后 ›</p>

但是当我单击页面上的分页 1 2 3 else 时,它​​会将我带到索引页面。

我需要在控制器的列表功能上。请任何人帮助我。


这是更新的代码

溃败代码是

$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"]);
4

2 回答 2

1

我找到了我的问题的解决方案

首先,我$this->uri->segment(3) and $config["uri_segment"] = 3;使用了错误的 uri->segment 进行分页。这解决了我与分页相关的问题。

我的下一部分是我必须使用分页为卖家或搜索结果设置变量。例如,我有doglist.html/?seller=29我需要用这个分页嵌入分页的 url。所以结果就像dog/list/3?breed=&gender=female&state=&submit2=Fetch我已经用这行代码解决了这个问题$config['suffix'] = '?'.http_build_query($_GET, '', "&");现在我的变量分页工作正常。

感谢@jtheman 和@Venkat,但主要是@jtheman 的贡献。

于 2012-12-01T16:26:22.510 回答
0

如果您对分页有任何疑问,请查看我写的这个通用函数作为另一个问题的答案。

于 2012-12-01T06:52:25.510 回答