Welcome Guest, Not a member yet? Register   Sign In
Problem with pagination -loading settings from file-
#1

[eluser]CARP[/eluser]
Hi
I'm trying to have different pagination settings (one for common listings, one for search results). I've the following code

Code:
...
$data = array();
$this->load->model(array('article_abm', 'category_abm'));
$this->load->library('pagination');

$config['total_rows'] = $this->article_abm->qtty($tabla);
$config['base_url'] = site_url().'/article/pub_by/' . $param1;

$this->config->load('pagination_alt');
[b]//$config['uri_segment'] = 4;
//$config['per_page'] = '10';[/b]
$this->pagination->initialize($config);

echo '<font size="5">Debugging! ' . $config['uri_segment'] . '</font>';

$data['pagination_links'] = $this->pagination->create_links();

$data['title'] = "Welcome to ...";

1. The config/pagination_alt.php file already has these two lines inside:
$config['uri_segment'] = 4;
$config['per_page'] = '10';
But I have to re put those lines in each pagination construction. I mean, these seems not to be loaded when loading pagination_alt config file

2. Of course echoing $config['uri_segment'] throws error Message: Undefined index: uri_segment

3. The pagination shows, and loads a "per_page" value of 10. Where is being this 10 taken from?

4. I don't have a pagination.php file inside config folder. I renamed it on purpose

5. $config array has only "total_rows" and "base_url" and not all the rest options theoretically loaded from config/pagination_alt.php

What could be wrong? How can I debug this?
#2

[eluser]pickupman[/eluser]
The pagination configuration is either/or not both. You either set it in pagination.php or you set it using the config array. When you call $this->pagination->initialize($config), you are overwriting any other setting, and not merging them. I tried doing what you are trying and it doesn't work that way. I wish it did. However, you can use part of the idea:
Code:
$config['per_page'] = $this->config->item('per_page'); // Set per_page key in your config.php
#3

[eluser]carvingCode[/eluser]
[quote author="pickupman" date="1272951121"]The pagination configuration is either/or not both. You either set it in pagination.php or you set it using the config array. When you call $this->pagination->initialize($config), you are overwriting any other setting, and not merging them. [/quote]

This isn't what I'm experiencing.

I'm setting many pagination config items (ones that affect open/close tags) in a 'config/pagination.php' file. Then setting 'per_page', 'total_rows', and 'base_url' in my controller method prior to calling '$this->pagination->initialize($config);'. Works fine.

I couldn't, for some reason, include 'per_page' in the 'config/pagination.php' file. That didn't work.
#4

[eluser]CARP[/eluser]
I think there's a problem in

$this->config->load('pagination_alt');
Because the $config array isn't being loaded as it should. I don't use pagination->initialize(..) when loading pagination settings from file, but I can't get the correct value from each config pagination item using $config[]...

Also tried doing
Code:
$this->config->load('pagination_alt');
$this->pagination->initialize($this->config);
without luck

PS: So, I ended up having this set of lines in each controller, for having different pagination settings in each controller function

Code:
$this->load->library('pagination');    
$this->config->load('pagination_alt');
$config['total_rows'] = $this->some_model->qtty_rows();
$config['base_url'] = site_url().'/controller/function/';

$config["per_page"]         = $this->config->item("per_page");
$config["uri_segment"]         = $this->config->item("uri_segment");
$config["num_links"]         = $this->config->item("num_links");
$config["first_link"]         = $this->config->item("first_link");
$config["last_link"]         = $this->config->item("last_link");
$config["next_link"]         = $this->config->item("next_link");
$config["prev_link"]         = $this->config->item("prev_link");
$config["full_tag_open"]     = $this->config->item("full_tag_open");
$config["full_tag_close"]     = $this->config->item("full_tag_close");
$config["first_tag_open"]     = $this->config->item("first_tag_open");
$config["first_tag_close"]     = $this->config->item("first_tag_close");
$config["last_tag_open"]     = $this->config->item("last_tag_open");
$config["last_tag_close"]     = $this->config->item("last_tag_close");
$config["next_tag_open"]     = $this->config->item("next_tag_open");
$config["next_tag_close"]     = $this->config->item("next_tag_close");
$config["prev_tag_open"]     = $this->config->item("prev_tag_open");
$config["prev_tag_close"]     = $this->config->item("prev_tag_close");
$config["cur_tag_open"]     = $this->config->item("cur_tag_open");
$config["cur_tag_close"]     = $this->config->item("cur_tag_close");
$config["num_tag_open"]     = $this->config->item("num_tag_open");
$config["num_tag_close"]     = $this->config->item("num_tag_close");
$this->pagination->initialize($config);
#5

[eluser]pickupman[/eluser]
I suppose if you are customizing each tag for the pagination class, why not extend the Pagination class and set your own defaults.
/application/libraries/MY_Pagination.php
Code:
class MY_Pagination extends CI_Pagination {
   var $cur_tag_open = ''; //Your default value
   var $cur_tag_close = ''; //Your default value
   //more variables

   function MY_Pagination( $params = array() ){
      parent::CI_Pagination();
      if (count($params) > 0)
      {
        $this->initialize($params);
      }
      log_message('debug', "Pagination Class Initialized");
   }
}
#6

[eluser]CARP[/eluser]
@pickupman
I've tried your solution, but I can't think about a solution where I could use one of 2 (or more) sets of pagination variables values in each controller, because the pagination class can be only extended once




Theme © iAndrew 2016 - Forum software by © MyBB