【问题标题】:Cakephp 3: Paginator linksCakephp 3:分页器链接
【发布时间】:2016-02-02 20:37:42
【问题描述】:

这是我的 index() 函数:

$this->paginate = [
        'conditions' => [
            'Items.state_id' => $state,
        ],
        'contain' => ['Accounts', 'Creditors', 'States', 'Bankaccounts' => ['joinType' => 'LEFT']],
        'order' => ['Items.account_id ASC', 'Items.creditor_id ASC', 'Items.payuntil ASC']
    ];
    $this->set('items', $this->paginate($this->Items));
    $this->set('_serialize', ['items']);

在我想使用第 2 页的分页链接之前,它可以正常工作:

我的看法:

<div class="paginator">
    <ul class="pagination">
        <?= $this->Paginator->prev('< ' . __('vorherige')) ?>
        <?= $this->Paginator->numbers() ?>
        <?= $this->Paginator->next(__('nächste') . ' >') ?>
    </ul>
    <p><?= $this->Paginator->counter('Seite {{page}} von {{pages}}') ?></p>
</div>

这是浏览器中的输出:

<a href="/items?page=2&amp;sort=0&amp;direction=Items.account_id+ASC">2</a>

但是这样会导致sql错误:

    WHERE 
  Items.state_id = 1 
ORDER BY 
  asc 
LIMIT 
  20 OFFSET 0

有一个空的 ORDER BY 选项。

如果我将上述链接更改为仅:/items?page=2 它按预期工作。

那么这里有什么问题呢? 我怎样才能解决这个问题? 请指教:-)

【问题讨论】:

    标签: cakephp pagination


    【解决方案1】:

    正确的语法是

    'order' => ['Items.account_id' => 'ASC', 'Items.creditor_id' => ' ASC', 'Items.payuntil' => ' ASC']
    

    您将停止收到错误,但您会发现此问题:

    https://github.com/cakephp/cakephp/issues/7324

    【讨论】:

    • 太棒了!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多