【问题标题】:"order by" not working with model in CakePHP 2.6 Pagination“order by”不适用于 CakePHP 2.6 分页中的模型
【发布时间】:2023-03-05 11:49:01
【问题描述】:

我正在尝试修改此代码以对结果进行排序:

$result = $this->Paginate('ReceivedCargo', 
    array('PNR_BROKERS' => $id )
);`

我试过了:

$result = $this->Paginate('ReceivedCargo', 
    array('PNR_BROKERS' => $id),               
    array('ReceivedCargo.PNR' => 'desc')
);

我做错了什么?

【问题讨论】:

  • 请告诉我如何解决它

标签: php cakephp pagination cakephp-2.x


【解决方案1】:

尝试以下方法:

$this->Paginator->settings['ReceivedCargo']['conditions']['PNR_BROKERS']=$id
$this->Paginator->settings['ReceivedCargo']['order']=array(
    'ReceivedCargo.PNR' => 'DESC'
);
$result = $this->Paginator->paginate('ReceivedCargo');

顺便说一句,$this->Paginate() 已被弃用(提供向后兼容性)。您应该直接访问PaginatorComponent。

有关详细信息,请参阅:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    • 2013-10-01
    • 1970-01-01
    • 2018-03-31
    • 2019-11-22
    • 1970-01-01
    相关资源
    最近更新 更多