Welcome Guest, Not a member yet? Register   Sign In
Pagination configuration problems.
#1

[eluser]aquary[/eluser]
I'm new to CodeIgniter, but so far so good Yet there is a problem I can't solve here

I've read the user guide and know that I can put my pagination preference in config/pagination.php. But if I use it, how can I set the url, total rows, and data per page? They are all different in each page. I tried setting them before calling $this->pagination->create_links(), yet it didn't work since its configuration went to the preference file.

Any suggestion? Thank you Smile.
#2

[eluser]xwero[/eluser]
You can use a config file to store the variables that apply everywhere. i think one config setting with an array is best, then you can merge it with an array with variable settings.
Code:
$this->pagination->initialize(array_merge($this->config->item('pagination'),array('base_url'=> 'http://example.com/index.php/test/page/','total_rows'=>200)));

The new Form_validation library in SVN has a feature where you can define validation groups and even controller/method in a config file so maybe the EL developers could do the same for the pagination library.
#3

[eluser]Bramme[/eluser]
You don't have to do that xwero...

Code:
$total_rows = $query->num_rows();
$per_page = 5;

$pagination_config['base_url']         = 'http://www.mickm.com/'.$type.'/offset/';
$pagination_config['total_rows']     = $total_rows;
$pagination_config['per_page']         = $per_page;

$this->pagination->initialize($pagination_config);
This is an example directly from a controller of mine. And then I have a config item too.

pagination.php:
Code:
<?php
    $config['full_tag_open']     = '<p id="pagination">';
    $config['full_tag_close']    = '</p>';
    $config['num_links']         = 3;
    $config['first_link']         = ' |&lt; First ';
    $config['prev_link']         = ' &lt; Prev ';
    $config['next_link']         = ' Next &gt; ';
    $config['last_link']         = ' Last &gt;| ';
    $config['first_tag_open']     = '';
    $config['first_tag_close']    = '';
    $config['last_tag_open']    = '';
    $config['last_tag_close']    = '';
    $config['cur_tag_open']     = '<span>';
    $config['cur_tag_close']    = '</span>';
    $config['next_tag_open']     = '';
    $config['next_tag_close']    = '';
    $config['prev_tag_open']     = '';
    $config['prev_tag_close']     = '';
    $config['num_tag_open']     = '';
    $config['num_tag_close']     = '';
?&gt;

Works like a charm!

Mind you, you do have to set some config items in your controller now, but personally I don't mind... I only put stuff in config files if it's the same for the entire site.




Theme © iAndrew 2016 - Forum software by © MyBB