在CodeIgniter中使用分页时出错

时间:2014-06-09 10:10:20

标签: php codeigniter codeigniter-2 codeigniter-url codeigniter-routing

我在CodeIgniter中遇到了分页问题: 我的路线是:

$route['tv/bloc']                     = "tv/about";
$route['tv/bloc/page/(:any)']        = "tv/about";
$route['tv/bloc/(:any)']              = "tv/view/$1";

在我的控制器中:

$config["base_url"] = base_url()."tv/bloc/page/";
$config["total_rows"] = $this->site_tv->record_count();
$config["per_page"] = 24;
$config["uri_segment"] = 4;
$choice = $config["total_rows"] / $config["per_page"];
$config ["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(4))? $this->uri->segment(4) : 0;

分页适用于分页2,3和4,但当我想返回分页的第一页时,我收到错误,因为控制器正在尝试搜索url /page...

是否有解决方案可以帮助我解决问题?

2 个答案:

答案 0 :(得分:0)

手动设置首页的网址:

$config['first_url'] = 'tv/bloc/page/1'; 
// Your code..
$config["base_url"] = base_url()."tv/bloc/page/";
$config["total_rows"] = $this->site_tv->record_count();
//  ....
$this->pagination->initialize($config);

答案 1 :(得分:0)

保留此代码段以备将来使用:

    $paging_config = array();
    $paging_config["base_url"] = site_url() . '/p/';
    $paging_config["total_rows"] = $this->qosasah_model->snippets_count();
    $paging_config["per_page"] = 10;
    $paging_config["uri_segment"] = 2;
    $paging_config['use_page_numbers']  = FALSE;

    /* This Application Must Be Used With BootStrap 3 *  */
    $paging_config['full_tag_open'] = "<ul class='pagination pagination-right'>";
    $paging_config['full_tag_close'] ="</ul>";
    $paging_config['num_tag_open'] = '<li>';
    $paging_config['num_tag_close'] = '</li>';
    $paging_config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
    $paging_config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
    $paging_config['next_link'] = 'Next';
    $paging_config['prev_link'] = 'Previous';       
    $paging_config['next_tag_open'] = "<li>";
    $paging_config['next_tagl_close'] = "</li>";
    $paging_config['prev_tag_open'] = "<li>";
    $paging_config['prev_tagl_close'] = "</li>";
    $paging_config['first_link'] = 'First';     
    $paging_config['first_tag_open'] = "<li>";
    $paging_config['first_tagl_close'] = "</li>";
    $paging_config['last_link'] = 'Last';       
    $paging_config['last_tag_open'] = "<li>";
    $paging_config['last_tagl_close'] = "</li>";

注意:这与bootstrap 3完美配合。因此,如果您不使用引导程序,则只需删除不需要的配置。