Welcome Guest, Not a member yet? Register   Sign In
Pagination configuration bug or incorrect documentation?
#1

[eluser]sparky672[/eluser]
At the bottom of this page: http://ellislab.com/codeigniter/user-gui...ation.html

Quote:If you want to add a class attribute to every link rendered by the pagination class, you can set the config "anchor_class" equal to the classname you want.

So I set the config option to the class name as instructed:

Code:
$config['anchor_class'] = 'page';

However, the rendered code was not at all as expected:

Code:
<a pagehref="/controller/2">2</a>

Either the wording in the documentation is completely wrong, or there's a bug someplace.

Alternatively, this is ugly:

Code:
$config['anchor_class'] = 'class="page"';

And yet it's still not quite correct:

Code:
<a class="page"href="/controller/2">2</a>

Notice there is a space missing between the 'class' and 'href' attributes.

This is the only way it gives the proper HTML:

Code:
$config['anchor_class'] = 'class="page" ';

And that's really nothing like what's described in the docs: "set the config 'anchor_class' equal to the classname"

Thank-you!

BTW: Perhaps this forum's anti-spam routines should be tweaked to allow posting of URL's that contain "ellislab dot com".

--------

EDIT:

I'm now convinced this is a bug.

The above problem only occurs when the configuration is declared dynamically within my Controller function and then set with `initialize($config)`.

I accidentally discovered that when a `pagination.php` config file is used instead, then it works exactly as described in the documentation.
#2

[eluser]TheFuzzy0ne[/eluser]
You're right. It does seem to be a bug. However, this will be fixed in CodeIgniter 3.0. https://github.com/EllisLab/CodeIgniter/...d8251480a1

You can post www.ellislab.com/ links. I think the problem you experienced seems to happen if you take too long to submit the form (CSRF protection).
#3

[eluser]Harold Villacorte[/eluser]
This fixes the bug. The code in the constructor doesn't work so it has to happen in the initialize method.
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Extends the CodeIgniter Pagination library.
*/
class MY_Pagination extends CI_Pagination
{
    /**
  * Initialize Preferences
  *
  * @access public
  * @param array initialization parameters
  * @return void
  */
function initialize($params = array())
{
  if (count($params) > 0)
  {
   foreach ($params as $key => $val)
   {
    if (isset($this->$key))
    {
     $this->$key = $val;
    }

    //------- The extension  ------------------------------------------//
    if ($key == 'anchor_class' && $val != '')
    {
        $this->anchor_class = 'class="' . $val . '" ';
    }
    //------- End extension  ------------------------------------------//

   }
  }
}
}
// END MY_Pagination Class

/* End of file MY_Pagination.php */
/* Location: ./application/libraries/MY_Pagination.php */
#4

[eluser]TheFuzzy0ne[/eluser]
Alternatively:

1) Create file: ./application/libraries/Pagination.php
2) Insert the code for the latest version: [url="https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Pagination.php"]here[/url]
3) Profit.

By doing this, you take advantage of any optimisations in the latest version, as well as any other bug fixes. It would also result in one less file load. It'll hardly boost your server efficiency by 10%, but it's definitely a bonus. Smile
#5

[eluser]Harold Villacorte[/eluser]
4) It looks like the new library lets you pass in an array of attributes as well. Much needed when working with front end frameworks.
#6

[eluser]sparky672[/eluser]
Thank-you both!




Theme © iAndrew 2016 - Forum software by © MyBB