fusic/flexlimitpagination

此包的最新版本(0.3.3)没有提供许可证信息。

CakePHP的Flexpager插件

安装: 62

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 1

开放问题: 3

类型:cakephp-plugin

0.3.3 2017-04-04 02:16 UTC

This package is auto-updated.

Last update: 2024-09-13 09:47:41 UTC


README

维护者: @gorogoroyasu

安装

composer require fusic/Flexpager

描述

此插件将帮助您创建分页的候选列表。例如:

普通分页器

< prev  1 2 3 4 5 next >

此分页器

< prev 1 2 3 4 5 next> 10 20 100

"10"、"20"、"100"表示您的应用程序可以使用户灵活地更改分页限制。

设置

首先,您必须加载组件。然后,您必须在public $paginate中写入"listCandidates"。

在控制器中


public $paginate = [
    'listCandidates' = [10, 20, 100],
    // and more configs.
];
public function initialize()
{
    parent::initialize();
    $this->loadComponent('Flexpager.Flexpager');
}

之后,您必须将此行添加到AppView.php中

public function initialize()
{
    parent::initialize();
    $this->loadHelper('Flexpager.Flexpaginator');
}

使用方法

在控制器中(例如在index中)

public function index()
{
    $pages = $this->Flexpager->paginate($this->Pages);
    $this->set(compact('pages'));
}

在ctp中(例如在index中)

<?= $this->Flexpaginator->prev('< '.__('previous')) ?>
<?= $this->Flexpaginator->numbers() ?>
<?= $this->Flexpaginator->next(__('next').' >') ?>
<?= $this->Flexpaginator->limitCandidate() ?>

limitCandidate()方法将返回候选列表。

如果您想自定义模板,可以使用以下方法。

<?= $this->Flexpaginator->setFlexPagerTemplate('<a class="form-control" href={{url}}>{{content}}</a>') ?>

此方法必须包含'{{url}}'和'{{content}}'参数。

默认模板是'<a href={{url}}>{{content}}</a>'

请注意,setFlexPagerTemplate方法应在listCandidates方法之前出现。