我在按不同模型的字段对表数据进行排序时遇到一些问题。
从这里: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 echo $this->Paginator->sort('Unit.unit', 'Unit');
无需传递第三个参数
model
选项即可完美工作。
新版本的提醒:关联模型不会自动加载到 CakePHP3s Paginator 中。确保包含“sortWhitelist”选项,请参阅https://book.cakephp.org/3.0/en/controllers/components/pagination.html#control-which-fields-used-for-ordering
请尝试以下代码
echo $this->Paginator->sort('Unit.unit', 'Unit', array('model' => 'Unit'));
如果有请告诉我。