Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Change pagination template on some controller
  • Hi guys,

    I have two pagination template, and want to set the template to use in a controller, right before using it.

    Tried for some time to set up config, but nothing's working.

    Is it possible ?

  • Where is your alternative config stored?

    If in the pagination config file using

    'myconfig' = array(

    you can load that using

    $pagination = \Pagination::forge('myconfig');

    If your config is elsewhere and you have it in an array, you can use

    $pagination = \Pagination::forge('myconfig', $myconfig);

    If you want to push it, you could even do

    $pagination = \Pagination::forge();
    foreach ($myconfig as $key => $value)
        $pagination->{$key} = $value;
  • Note that pagination is a multiton.

    So when you do

    $p1 = \Pagination::forge();
    $p2 = \Pagination::forge();

    $p1 is equal to $p2, and anything you change in one will also change in the other.
  • I'm not sure that you understood my problem (or I didn't understand your answer). I'm talking about pagination template, not the config you give to the pagination instance. 

    The two templates I have are located in app/config/pagination.php, and the active template is defined in the 'active' config key in that file. (Which is 'default' by default)

    This is what I want to be able to change. But if you set the 'active' property in the config you pass to your pagination instance, it set the active link, and not the template to use. 

  • Yes, I understand that.

    The 'active' value is just to set the template definition you want to load by default, i.e. if you don't explictly ask for one. It is not there to set at runtime, but to default your default.

    In the default pagination config file (in fuel/core), there are 3 templates defined: 'default', 'bootstrap' and 'bootstrap3'.

    If you want to use 'bootstrap3', you would use

    $pagination = \Pagination::forge('myinstance', 'bootstrap3');
  • Thanks for your answer but I still dont get it, given that the function's signature is the following :

    I tried your example 

    $pagination = \Pagination::forge('myinstance', 'bootstrap4');

    But it doesn't work since I don't pass config then. Can you give me a working example of different template with this example ?

    $config = [
           'pagination_url' => '/blog/p',
           'total_items'    => $count,
           'per_page'       => 4,
           'uri_segment'    => 3,
    $pagination = Pagination::forge( 'mypagination', $config );

    Thanks again.
  • HarroHarro
    Accepted Answer
    You assume here that the config is only used to pass parameters. This is not the case, all variables that are used to generate the pagination are part of the config array. And that includes all the keys that provide the HTML, as defined in the config file.

    For example, in apps that use bootstrap, we use font-awesome instead of HTML entities for the markers, so we do something like:

    $template = array(
        // we use bootstrap v3
        'name' => 'bootstrap3',

        // but with font awesome graphic markers
        'first-marker'            => "<i class=\"fa fa-fast-backward\"></i>",
        'previous-marker'         => "<i class=\"fa fa-backward\"></i>",
        'next-marker'             => "<i class=\"fa fa-forward\"></i>",
        'last-marker'             => "<i class=\"fa fa-fast-forward\"></i>",

    $config = array(
        'pagination_url' => '/blog/p',
        'total_items'    => $count,
        'per_page'       => 4,
        'uri_segment'    => 3,

    $pagination = Pagination::forge( 'mypagination', $template + $config );

    (note: this is simplyfied for sake of the example).

    The 'name' is part of the config to override the 'active' definition is the config, if that would not be there, Pagination would load the active template as the basis, and we want it to use the bootstrap3 template as the basis.

    This works fine for simple adjustments. If you have an entirely different template, it is better to define it in your app/config/pagination.php config file, and set 'active' to load it by default.
  • Alright, awesome help as always Harro !


Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion