-1

我有一个正确过滤的搜索页面,但是当它分页时,您会丢失数据,因为我正在发布它。所以我将它切换为 GET,但我不知道如何添加我传递回分页器的 http_build_query( $params )。

我尝试在选项的分页器 url 中设置查询参数,但没有运气,API 没有提到添加查询参数。

如何设置搜索结果查询参数,以便不同的页面知道它们被过滤的内容?因此,对 name=steve 和 company=SomeCompany 的搜索将通过第 2、3、4 页进行维护,每页有 10 个结果,并且不会重置为显示所有未过滤的 100 个结果。

控制器中的简单示例分页

$this->paginate = [
    'limit'      => 5,
    'order'      => [ 'CollectionAgencyAgent.id' => 'desc' ]
];

return $this->paginate( $this->CollectionAgencyAgent, $conditions );

带分页查看

<ul class="pagination <?php echo $class ?>">

    <?php
    $this->Paginator->options( [
        'url' => [
            'controller' => ''
        ]
    ] );
    ?>

    <?php echo $this->Paginator->prev( __( '&laquo; Previous' ), [
        'escape'      => false,
        'tag'         => 'li',
        'class'       => 'arrow',
        'disabledTag' => 'a'
    ] ); ?>

    <?php echo $this->Paginator->numbers( [
        'separator'  => '',
        'tag'        => 'li',
        'currentTag' => 'a'
    ] ); ?>

    <?php echo $this->Paginator->next( __( 'Next &raquo;' ), [
        'escape'      => false,
        'tag'         => 'li',
        'class'       => 'arrow',
        'disabledTag' => 'a'
    ] ); ?>
</ul>
4

1 回答 1

2

分页器类自动合并当前请求参数

public function beforeRender($viewFile) {
    $this->options['url'] = array_merge($this->request->params['pass'], $this->request->params['named']);
    if (!empty($this->request->query)) {
        $this->options['url']['?'] = $this->request->query;
    }
    parent::beforeRender($viewFile);
}

所以简短的回答是什么都不做,这样就行了。

它不适用于问题中的代码的原因是这个调用:

$this->Paginator->options( [
    'url' => [
        'controller' => ''
    ]
] );

这将消除分页器的运行时 url 选项。因此,为了防止问题中的问题 - 只需删除该呼叫(然后,可能修复提示您添加它的路由问题=))。

于 2015-10-02T08:02:34.287 回答