简体   繁体   中英

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?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM