0
votes

I want to add ajax paging in CI_pagination class, but for this I want to create a class MY_Pagination which extends the CI_Pagination class but it gives error when I use this library by $this->load->library('pagination'); in my controller: and calling the test function in new MY_Pagination Class

Fatal error: Call to undefined method CI_Pagination::test() ...

I also added the line $config['subclass_prefix'] = 'MY_'; in config.php I changed the sub class name because of Please note that all native CodeIgniter libraries are prefixed with CI_ so DO NOT use that as your prefix. on http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

Here is my code

<?php
class MY_Pagination extends CI_Pagination {

    function __construct() {
        parent::__construct();
    }
    function test()
    {
       echo 'test';
    }
}
?>

This code is saved in a file MY_Pagination.php.

I read the document from https://www.codeigniter.com/user_guide/general/creating_libraries.html but this not works why?

2

2 Answers

1
votes

Load the CI_Pagination class before you try to extend it, so

$this->load->library('pagination'); // base class
$this->load->library('ajax_pagination'); // custom derived class
0
votes

Why are you building a library for Pagination.

Codeigniter already has a pagination library

Refer this

http://ellislab.com/codeigniter/user-guide/libraries/pagination.html