2016年4月24日日曜日

cakephp3 ページネーション -- Pagination method --

PHP Ver 5.6.27
CakePHP Ver 3.1.9



cakephp3 ページネーション (Cake\View\Helper\PaginatorHelper)


利用できるメソッド一覧

基本的には以下のように利用する。
$this->Paginator->{methodName}

・templates($templates = null)
    $templates = [
        'nextActive' => '< li class="next">< a rel="next" href="{{url}}">{{text}}< /a>< /li>',
        'nextDisabled' => '< li class="next disabled">< a href="" onclick="return false;">{{text}}< /a>< /li>',
        'prevActive' => '< li class="prev">< a rel="prev" href="{{url}}">{{text}}< /a>< /li>',
        'prevDisabled' => '< li class="prev disabled">< a href="" onclick="return false;">{{text}}< /a>< /li>',
        'counterRange' => '{{start}} - {{end}} of {{count}}',
        'counterPages' => '{{page}} of {{pages}}',
        'first' => '< li class="first">< a href="{{url}}">{{text}}< /a>< /li>',
        'last' => '< li class="last">< a href="{{url}}">{{text}}< /a>< /li>',
        'number' => '< li>< a href="{{url}}">{{text}}< /a>< /li>',
        'current' => '< li class="active">< a href="">{{text}}< /a>< /li>',
        'ellipsis' => '< li class="ellipsis">...< /li>',
        'sort' => '< a href="{{url}}">{{text}}< /a>',
        'sortAsc' => '< a class="asc" href="{{url}}">{{text}}< /a>',
        'sortDesc' => '< a class="desc" href="{{url}}">{{text}}< /a>',
        'sortAscLocked' => '< a class="asc locked" href="{{url}}">{{text}}< /a>',
        'sortDescLocked' => '< a class="desc locked" href="{{url}}">{{text}}< /a>',
    ];

・sort($key, $title = null, array $options = [])
    $key(string)
    $title(string)
    $options = [
        'url' => [],
        'model' => 'defaultModel',
        'escape' => true,
    ];

・sortDir($model = null, array $options = [])
    $model = {modelName}
    $options = [
        'url' => [
            'sort' => 'email',
            'direction' => 'desc',
            'page' => 6,
            'lang' => 'en',
        ]
    ];

・sortKey($model = null, array $options = [])
    $key(string)
    $options = [
        'url' => [
            'sort' => 'email',
            'direction' => 'desc',
            'page' => 6,
            'lang' => 'en',
        ]
    ];

・numbers(array $options = [])
    $options = [
        'before' => {numbers},
        'after' => {numbers},
        'model' => 'defaultModel',
        'modulus' => 8,
        'first' => 'First page',
        'last' => 'Last page',
        'templates' => [
            'active' => 'nextActive',
            'disabled' => 'nextDisabled',
        ],
        'url' => [],
    ];

・prev($title = '<< Previous', array $options = [])
    $title(string)
    $options = [
        'disabledTitle' => {title},         'url' => [],
        'model' => 'defaultModel',
        'escape' => true,
        'templates' => [
            'active' => 'nextActive',
            'disabled' => 'nextDisabled',
        ]
    ];

・next($title = 'Next >>', array $options = [])
    $title(string)
    $options = [
        'disabledTitle' => {title},         'url' => [],
        'model' => 'defaultModel',
        'escape' => true,
        'templates' => [
            'active' => 'nextActive',
            'disabled' => 'nextDisabled',
        ]
    ];

・first($first = '<< first', array $options = [])
    $first(string or int)
    $options = [
        'url' => [],
        'model' => 'defaultModel',
        'escape' => true,
    ];

・last($last = 'last >>', array $options = [])
    $last(string or int)
    $options = [
        'url' => [],
        'model' => 'defaultModel',
        'escape' => true,
    ];

・counter($options = [])
    $options = [
        'model' => 'defaultModel', // デフォルトではPaginatorHelper::defaultModelが呼ばれる
        'format' => 'range' or 'pages' or custom
            custom example: 'Page {{page}} of {{pages}}, showing {{current}} records out of
                {{count}} total, starting on record {{start}}, ending on {{end}}'
        ];

・current($model = null)
    $model = {modelName}

・hasNext($model = null)
    $model = {modelName}

・hasPage($model = null, $page = 1)
    $model = {modelName}
    $page = int
・hasPrev($model = null)
    $model = {modelName}

・options(array $options = [])
    $options = [
        'url' => [
            'sort' => 'email',
            'direction' => 'desc',
            'page' => 6,
            'lang' => 'en',
        ]
    ];

・generateUrl(array $options = [], $model = null, $full = false)
    $options = [
        'page' => null,
        'sort' => null,
        'direction' => null,
        'limit' => null,
    ];
    $model = {modelName}
    $full = boolean

・meta(array $options = [])
    $options = [
        'model' => 'defaultModel', // デフォルトではPaginatorHelper::defaultModelが呼ばれる
        'block' => false or {blockName},
    ];

0 件のコメント:

コメントを投稿