0

I am working on the codeigniter as a beginner,, and got this problem.. I cannotload the Pagination Library...

Here is the code

<?php

/**
* 
*/
class Site extends CI_Controller
{
public function index() {

    if($this->load->library('pagination')) {
        echo "load success";
    }
    else {
        echo "load failed";
    }

    $config['base_url'] = 'http://localhost/ci_pagination/index.php/site/index';
    $config['total_rows'] = $this->db->get('data')->num_rows();
    $config['per_page'] = 10;
    $config['num_links'] = 20;

    $this->pagination->initialize($config);
    echo $this->pagination->create_links();

    $data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));

    $this->load->view('site_view', $data);
}

}

?>

I even tried autoloading pagination library.. But still it is echoing 'Load Failed' . CAN SOMEBODY HELP ME???????? plzzzzzz

2
  • And what does it say? What error you get?
    – Kyslik
    Jan 11, 2015 at 14:57
  • No, its not error. Actually it is not loading the pagination library, that's is why it is not displaying the pagination links. Actually, this code if($this->load->library('pagination')) { echo "load success"; } else { echo "load failed"; } is outputting 'load failed'. So, that's why i guessed may be the pagination library is not loading.. Jan 11, 2015 at 15:07

1 Answer 1

1

You need to check your code, load function does not return boolean value (it returns NULL or error), therefore your if() statement is always false, in fact you can check in CodeIgniter logs after you turn on log_threshold config value to 2 - DEBUG.

It looks like this:

DEBUG - 2015-01-11 16:51:11 --> Pagination Class Initialized

testing code I am working with:

public function pagination() {
    var_dump( $this->load->library('pagination') );
}

Further more you want this line in your view file instead of controller itself.

echo $this->pagination->create_links();

Please do your homework before asking here next time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.