蛋糕分页器 ->排序 - 模型选项



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

从这里: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]

知道这里发生了什么吗?主/默认型号为Card,我需要按其中一列标题的单位型号订购。

感谢

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

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

它将在不传递第三个参数model选项的情况下完美工作。

提醒更新版本:关联模型不会自动加载到CakePHP3的分页器中。请确保包含"sortWhitelist"选项,请参阅https://book.cakephp.org/3.0/en/controllers/components/pagination.html#control-用于排序的字段

请尝试以下代码

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

如果有,请告诉我。

最新更新