Packiya Rajan
Packiya Rajan

Reputation: 59

CodeIgniter pagination library does not load on a particular controller

CodeIgniter's pagination library is not loading in a particular controller of my project, the same piece of code works fine in other controllers of the same project.

Here is the code that loads correctly: (controller name : Purchases)

    // load pagination library
    $this->load->library('pagination');

    //configure pagination
    $page_config['base_url']         = base_url('purchases/list_all');
    $page_config['total_rows']       = $total_no_of_purs;
    $page_config['per_page']         = $no_of_purs_per_page;
    $page_config['uri_segment']      = 3;
    $page_config['use_page_numbers'] = TRUE;

    //initialize pagination
    $this->pagination->initialize($page_config);

and Here follows the code that fails to load pagination library (Controller Name: Employee)

    //load pagination library
    $this->load->library('pagination');

    //configure pagination
    $page_config['base_url']         = base_url('employee/list_all');
    $page_config['total_rows']       = $total_no_of_emps;
    $page_config['per_page']         = $no_of_emps_per_page;
    $page_config['uri_segment']      = 3;
    $page_config['use_page_numbers'] = TRUE;

    //initialize pagination
    $this->pagination->initialize($page_config);

I want to say that all the variables assigned to the config are valid. The error I am getting for the second piece of code is:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Employee::$pagination
Filename: controllers/employee.php
Line Number: 115

Line 115 is: $this->load->library('pagination');

In both the classes, the constructor was not loaded with the pagination library. Why does one work and the other not?

Upvotes: 4

Views: 945

Answers (3)

KBK
KBK

Reputation: 375

this error because of

$page_config['base_url'] = base_url('employee/list_all');

try this $page_config['base_url'] = base_url()."employee/list_all"; If not

** you need to define base_url(); first

Upvotes: 0

shankar kumar
shankar kumar

Reputation: 648

After seeing your coding related to pagination, I want to see your whole controller of employee as seems that extends in employee controller is missing and hence they are not able to load pagination class and hence please paste your complete employee controller here.

Thanks, Shankar

Upvotes: 0

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

$this->pagination->create_links(); only shows pagination when your $total_no_of_emps is greater than $no_of_emps_per_page.

Upvotes: 0

Related Questions