• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correct use of pagination class

#1
[eluser]J. Pavel Espinal[/eluser]
Hi folks,

I am new to CodeIgniter and it is the second PHP framework (after giving up trying to use CakePHP) that I use, and its simply marvelous (Excellent Job).

Please pardon my bad english (learned it at home with the aid of some books and a PlayStation Tongue ).

I am using the Pagination Class of CI and i see that in the documentation something like...
"The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it."
... is said about the "$config['uri_segment']" setting; but in my URI I am able to see only the offset number ( corresponding to the $config['per_page'] setting ); and none of them displays the 'current page'.

Am I missing something (or miss understanding something)?


PS.
So far I was using it this way (Which works fine, but I do not know if it is the correct way):

Code:
//-----------------------------------            
$this->load->library('pagination');
$config['base_url']     = 'http://10.0.0.200/ci/index.php/admin_main/view_rslr';
$config['total_rows']   = $this->db->count_all('resellers'); // The total here
$config['per_page']     = '5';                               // I was using this to navigate
$config['prev_link']    = '<';                             // through pages
$config['next_link']    = '>';

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

//-----------------------------------

// Look how i did this... is that correct? (I mean should it be that way?)
$result = $this->db->get('resellers', $config['per_page'], $this->uri->segment(3,0));

$data['pag_links']     = $this->pagination->create_links();
$data['result']        = $result->result_array();

//*******************************************//  
$this->load->view('admin/view_resellers', $data);
//*******************************************//


Thank you in advice :cheese:

#2
[eluser]MadZad[/eluser]
Jose,
I just tried the pagination class yesterday for the first time, so while I'm not much help in diagnosing problems (your code looks fine to me), I can point you at this thread: ellislab.com/forums/viewthread/70821/
Isern Palaus posted a nice example, and that's what I used to get myself going.

I can say that the number that CI pagination puts into the uri is the current offset, and it uses that to determine which page to display. So I would expect that you'd see 5, 10, 15... For no real good reason, I chose to put an argument on my controller, and I use that value instead of grabbing uri segment 3. Really is the same difference.

BTW, your English is just fine, and infinitely superior to any attempt I've ever made to speak another language.

Good luck.

#3
[eluser]J. Pavel Espinal[/eluser]
Thanks MadZad :lol: ,
I'll sheck the topics inmediatelly to grab some ideas about the use of CI Pagination class.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.