cakephp Paginator -> 排序 - 模型选项

问题描述 投票:0回答:3

我在按不同模型的字段对表数据进行排序时遇到一些问题。

从这里:http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html

它说我可以添加“模型”选项,但是当我尝试时:

echo $this->Paginator->sort('unit', 'Unit', array('model' => 'Unit'));

我收到此错误:

Warning (2): array_filter() expects parameter 1 to be array, null given [CORE/Cake/View/Helper/PaginatorHelper.php, line 395]

Warning (2): array_merge() [function.array-merge]: Argument #1 is not an array [CORE/Cake/View/Helper/PaginatorHelper.php, line 395]

知道这是怎么回事吗?主要/默认型号是卡,我需要按列标题之一的单位型号进行订购。

谢谢

php cakephp pagination
3个回答
2
投票

如果您要在某些表的列表中显示记录,那么您可以通过以下方式使用它:

<?php echo $this->Paginator->sort('Unit.unit', 'Unit');

无需传递第三个参数

model
选项即可完美工作。


1
投票

新版本的提醒:关联模型不会自动加载到 CakePHP3s Paginator 中。确保包含“sortWhitelist”选项,请参阅https://book.cakephp.org/3.0/en/controllers/components/pagination.html#control-which-fields-used-for-ordering


0
投票

请尝试以下代码

echo $this->Paginator->sort('Unit.unit', 'Unit', array('model' => 'Unit'));

如果有请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.