Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to I append search to pagination links?
  • Hello,

    pagination is working fine, but if I use get variable ($search) that results in 2 pages, the second page url only shows page=2, not page=2&search=whatever

    How do I append my search to the pagination links?

    Thanks
  • Update your local framework installation to either 1.7.3 (released last week) or switch to 1.8/develop.

    The issue was fixed here: https://github.com/fuel/core/commit/b952d60cac99137f973633238addd540790cf45d
  • Hi Harro,

    I downloaded 1.7.3 and replaced the core and packages folders.
    I might be upgrading wrong, as this did not resolve the issue.
    [code]
    $query = Model_Category::query();

    $search = INput::get('search');

    if (!empty($search))
    {
    $query->where('name','like','%'.$search.'%');
    }
    // ->rows_offset($pagination->offset)
        // ->rows_limit($pagination->per_page)
              //  ->get();

            $config = array(
        'pagination_url' =>  Uri::current(),
        'total_items'    => $query->count(),
        'per_page'       => 10,
        'uri_segment'    => 'page',
    );

            $data['pagination'] = Pagination::forge('mypagination', $config);
    $data['categories'] = $query
        ->limit($data['pagination']->per_page)
        ->offset($data['pagination']->offset)
        ->get();

    echo Pagination::instance('mypagination')->render();
    [/code]
  • HarroHarro
    Accepted Answer
    You are passing a "pagination_url".

    That will disable any URL detection by the pagination class, it will use the url you have defined, as you defined it.

    So either remove that and let the class construct the URL itself, or pass a URL in the config that includes the current query string.
  • Thank you, it is working now.

Howdy, Stranger!

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

In this Discussion