Welcome Guest, Not a member yet? Register   Sign In
Problem with pagination
#1

[eluser]Michal1[/eluser]
Hello guys, I am trying to learn something about pagination and it works really nice when I have it setup in my index function in the main controller.

However I want to make a special function for this in the main controller, so it would look little bit more cleaner. But I get an error.

What I have is:

Code:
class Site extends Controller {

   function index()

    {

      blablabla some coding and working with data array and models blablabla
      
            $this->load->view('site_view',$data);

    }

     function paginate()

    {

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

       $config['base_url'] = 'http://127.0.0.1:8888/index.php/site/paginate';
       $config['total_rows'] = '20';
       $this->pagination->initialize($config);


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


Then in the site_view I have

Code:
<?php echo $this->pagination->create_links(); ?>

But it says

Code:
Message: Undefined property: CI_Loader::$pagination

Fatal error: Call to a member function create_links() on a non-object in C:\Program Files\EasyPHP-5.3.3.1\www\application\views\site_view.php on line 23

Do you think somebody could explain that to me? As I am beginner. when i put into index function it works fine. I do not get it.

Thank you
#2

[eluser]Cristian Gilè[/eluser]
In the index function you call the site_view view but the pagination is not loaded, so

Code:
$this->pagination->create_links();

is not a valid call. You could load the pagination class in the controller constructor.

Cristian Gilè
#3

[eluser]Michal1[/eluser]
Thank you, could you please be more specific and write some example code. I am trying but as a beginner it is kinda hard.
#4

[eluser]Cristian Gilè[/eluser]
http://net.tutsplus.com/articles/news/co...agination/

Cristian Gilè
#5

[eluser]Atharva[/eluser]
[quote author="Michal1" date="1294983417"]Thank you, could you please be more specific and write some example code. I am trying but as a beginner it is kinda hard.[/quote]

In short, your are missing your pagination data. You will need two queries, one to grab the actual data, and second to calculate the total rows. The example url provided above will help you.




Theme © iAndrew 2016 - Forum software by © MyBB