Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination issue...
  • Hello,
    I have been working with fuelphp for about a
    week now and I really enjoy the framework. The only thing that I cannot seem to
    get is pagination. I have found a handful of examples online on how it
    should be implemented but nothing has worked for me. The is basically
    how I am setting things up.



            $config = array(
                'pagination_url' => 'http://localhost/fuelphp/',
                'total_items'    => Model_Post::count(),

                'per_page'       => 10,
                'uri_segment'    => 3,

            );

            $pagination = Pagination::forge('mypagination', $config);
            $data['example_data'] = $pagination;

            $data['posts'] = Model_Post::find('all',

                        array(
                         
                        'offset' => \Pagination::get('offset') ));

    I
    am able to verify little things like the Model_Post count being
    retrieved correctly and the $data['posts'] variable returns data, but
    every time I check $data['example_data'] I get an empty string and can't
    figure out why... Do I have to include anything special in my controller to use Pagination? This project is using the orm package. I am not sure if that makes a difference. Any help is greatly appreciated!
  • Only obvious thing I see at the moment is that you have defined an impossible uri_segment.

    Your pagination URL contains only 1 segment, so it can't create segment 3 (as 2 is missing).
  • Also, what do you intend to do with

    'offset' => \Pagination::get('offset') ));

    As you created a pagination object ($pagination) containing your configuration, you can't use static calls because they work on the default instance.

    You have to use

    'offset' => $pagination->offset

    instead.

Howdy, Stranger!

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

In this Discussion