Codeigniter Bootstrap分页

时间:2012-08-28 17:03:45

标签: codeigniter

我正在使用CodeIgniter和Twitter Bootstrap创建一个Web应用程序。我在网上找到了一个资源,其中包含$ config设置列表,可以正确设置分页链接的样式。有没有办法将它存储在库中并将其加载到控制器中,所以我不必每次都输入它?

5 个答案:

答案 0 :(得分:18)

您可以将其保存为application / config中的pagination.php:

$config['per_page'] = 2;
$config['uri_segment'] = 3;
$config['num_links'] = 9;
$config['page_query_string'] = TRUE;

$config['query_string_segment'] = 'page';

$config['full_tag_open'] = '<div class="pagination"><ul>';
$config['full_tag_close'] = '</ul></div><!--pagination-->';

$config['first_link'] = '&laquo; First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';

$config['last_link'] = 'Last &raquo;';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';

$config['next_link'] = 'Next &rarr;';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';

$config['prev_link'] = '&larr; Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';

$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';

$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';

$config['anchor_class'] = 'follow_link';

答案 1 :(得分:4)

非常简单的bootstrap和codeigniter解决方案

$this->load->model('reciever');
                $this->load->library('uri');
                $this->load->library('pagination');
                $config['base_url'] = base_url(). 'users_ci/users';
                $config['total_rows'] = $this->reciever->getRows();
                $config['per_page'] = 4;
                $config['full_tag_open'] = '<ul class="pagination">';
                $config['full_tag_close'] = '</ul>';            
                $config['prev_link'] = '&laquo;';
                $config['prev_tag_open'] = '<li>';
                $config['prev_tag_close'] = '</li>';
                $config['next_link'] = '&raquo;';
                $config['next_tag_open'] = '<li>';
                $config['next_tag_close'] = '</li>';
                $config['cur_tag_open'] = '<li class="active"><a href="#">';
                $config['cur_tag_close'] = '</a></li>';
                $config['num_tag_open'] = '<li>';
                $config['num_tag_close'] = '</li>';
                $config["num_links"] = round( $config["total_rows"] / $config["per_page"] );
                $config['users']= $this->reciever->getUsers(4,$this->uri->segment(3));
                $this->pagination->initialize($config);
                $config['pages'] = $this->pagination->create_links();
                $this->load->view('users',$config);

和视图你有

<div><?php echo $pages; ?></div>

答案 2 :(得分:0)

您始终只需在模型中创建一个带有设置数组的.php文件并require_once(),然后返回到分页启动器。或者最好创建一个模型/库,将所有设置都返回给你。

型号:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$pagination_config = array(
    'full_tag_open' = '<p>',
    'full_tag_close' = '</p>',
    // ...
);

class Pagiconf extends CI_Model {
    public function load() {
        $this->load->library('pagination');
        $this->pagination->initialize($config);
        return $this->pagination->create_links();
    }
}

您需要的任何地方:

$this->load->model('pagiconf');
echo $this->pagiconf->load();

答案 3 :(得分:0)

      The bellow working fine 



       $config["base_url"] = base_url() . "product/product/index1";
        $config["total_rows"] = $count_products;    

  $config['per_page'] = 2;
$config['uri_segment'] = 4;
$config['num_links'] = 9;

$config['full_tag_open'] = '<div class="pagination"><ul>';
$config['full_tag_close'] = '</ul></div><!--pagination-->';

$config['first_link'] = '&laquo; First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';

$config['last_link'] = 'Last &raquo;';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';

$config['next_link'] = 'Next &rarr;';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';

$config['prev_link'] = '&larr; Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';

$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';

$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';



        $this->pagination->initialize($config);

答案 4 :(得分:0)

这是我的Bootstrap v4.0的工作代码

$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] ='</ul>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li class="page-item"><a href="#" aria-label="Next">';
$config['next_tagl_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tagl_close'] = '</li>';
$config['first_tag_open'] = '<li class="page-item disabled">';
$config['first_tagl_close'] = '</li>';
$config['last_tag_open'] = '<li class="page-item"><a href="#" aria-label="Next">';
$config['last_tagl_close'] = '</a></li>';
$config['attributes'] = array('class' => 'page-link');