我是CodeIgniter框架中的新成員,我試圖用分頁顯示結果,但是我有一個分頁變量undefined
。Codeigniter分頁變量undefined
這裏是我的型號:
class Campaign_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function get_campaign_lists($limit, $start) {
$sql = 'SELECT * FROM ch_campaigns LIMIT '.$limit.', '.$start;
$query = $this->db->query($sql);
return $query->result();
}
}
控制器:
class Pagination extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->database();
$this->load->library('pagination');
$this->load->model('campaign_model');
}
public function index() {
//pagination settings
$config['base_url'] = site_url('pagination/index');
$config['total_rows'] = $this->db->count_all('ch_campaigns');
$config['per_page'] = "5";
$config["uri_segment"] = 1;
$choice = $config["total_rows"]/$config["per_page"];
$config["num_links"] = floor($choice);
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_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>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(1)) ? $this->uri->segment(1) : 0;
//call the model function to get the department data
$data['campaignlist'] = $this->campaign_model->get_campaign_list($config["per_page"], $data['page']);
$data['pagination'] = $this->pagination->create_links();
//load the department_view
$this->load->view('campaign_view',$data);
}
}
和查看:
<div class="main-container-footer text-center">
<?php echo $pagination; ?>
</div>
IM試着g現在解決這個錯誤一段時間,但仍然沒有運氣。請幫幫我。
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: pagination
Filename: views/campaign_view.php
Line Number: 26
Backtrace:
File: C:\xampp\htdocs\cheching\application\views\campaign_view.php
Line: 26
Function: _error_handler
File: C:\xampp\htdocs\cheching\application\controllers\Content.php
Line: 11
Function: view
File: C:\xampp\htdocs\cheching\index.php
Line: 315
Function: require_once
什麼是你所得到的確切的錯誤信息? –
@low_rents更新了問題。 –
@PedroOrdonez,似乎合理的期望這樣的錯誤信息。看着你的代碼,當你試圖在'<?php echo $ pagination中使用它時,你沒有在任何地方定義'$ pagination'變量; ?>'。 –