我想在FuelPHP中使用分页,我正在使用此代码:
$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;
以下是观点:
<?php echo Pagination::instance('mypagination')->previous(); ?>
<?php echo Pagination::instance('mypagination')->render(); ?>
<?php echo Pagination::instance('mypagination')->next(); ?>
<?php echo Pagination::instance('mypagination')->last(); ?>
但是当我尝试点击前端的任何分页时,它会发送错误:404 page not found
答案 0 :(得分:3)
您需要设置路线,以便燃料知道如何将URI admin/accounts/index/:page
映射到正确的控制器。
以下内容应该适用于您的routes.php
配置文件。 (可能需要根据您的应用进行调整)
'admin/accounts/index/:page' => 'admin/accounts/index'