I want to use pagination in FuelPHP, I'm using this code:

$config = array(
   'pagination_url' => 'http://localhost/live/public/index.php/admin/accounts/index/',
   'total_items'    => Model_Account::count(),
   'per_page'       => 10,
   'uri_segment'    => 3,
   // or if you prefer pagination by query string
   //'uri_segment'    => 'page',
);

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

$data['example_data'] = Model_Account::query()
                           ->rows_offset($pagination->per_page)
                           ->rows_limit($pagination->offset)
                           ->get();

// we pass the object, it will be rendered when echo'd in the view
$data['pagination'] = $pagination;

and here's the view:

<?php echo Pagination::instance('mypagination')->previous(); ?>
<?php echo Pagination::instance('mypagination')->render(); ?>
<?php echo Pagination::instance('mypagination')->next(); ?>
<?php echo Pagination::instance('mypagination')->last(); ?>

But when I try to click on any pagination in frontend then it sends error: 404 page not found

有帮助吗?

解决方案

You will need to have a route set up so fuel knows how to map the URI admin/accounts/index/:page to the correct controller.

Something like the below should work in your routes.php config file. (Might need tweaking depending on your app)

'admin/accounts/index/:page' => 'admin/accounts/index'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top