2012-08-28 103 views
4

我正在用CodeIgniter和Twitter Bootstrap製作一個web應用程序。我在網上找到了一個包含$ config設置列表的資源,以正確設置分頁鏈接的樣式。有沒有辦法將它存儲在庫中並將其加載到控制器中,這樣我就不必每次都輸入它了?Codeigniter Bootstrap分頁

回答

18

您可以將此保存爲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'; 
+3

很有用...謝謝:) –

+3

@mpet ...我的工作代碼哇驚人和非常簡單的解決方案你節省了我的時間。我只是想發表這個問題。非常感謝你。 – Zohaib

+3

非常感謝 - 完美的作品! – fjckls

0

您可以隨時簡單地使用settings數組創建一個.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(); 
4

的引導非常簡單的解決方案和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> 
+0

我寫過關於Cdeigniter分頁的教程。請看看並提出建議https://www.cloudways.com/blog/pagination-in-codeigniter/ –

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); 
0

這裏是引導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');