Pedro Ordonez Pedro Ordonez - 1 year ago 134
PHP Question

Codeigniter pagination variable undefined

I'm new in CodeIgniter Framework, I'm trying to display the result with pagination but I'm having a pagination variable


Here is my Model:

class Campaign_model extends CI_Model {

public function __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() {

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'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$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>';

$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

and the View:

<div class="main-container-footer text-center">
<?php echo $pagination; ?>

im trying to fix this error for awhile now but still no luck. please help me.

A PHP Error was encountered
Severity: Notice

Message: Undefined variable: pagination
Filename: views/campaign_view.php
Line Number: 26
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

Answer Source

I think you should add at the beginning of controller's method index() the following line:

public function index() {

    $data = array();

    // [...] index method implementation.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download