【问题标题】:cakephp Paginator -> sort - model optioncakephp 分页器 -> 排序 - 模型选项
【发布时间】:2012-08-29 16:44:06
【问题描述】:

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

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

知道这里发生了什么吗?主要/默认模型是卡片,我需要按单元模型为列标题之一排序。

谢谢

【问题讨论】:

    标签: cakephp pagination


    【解决方案1】:

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

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

    无需传递第三个参数model 选项即可完美运行。

    【讨论】:

    • 我很乐意提供帮助。随时询问... :)
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      请尝试以下代码

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

      如果有请告诉我。

      【讨论】:

        猜你喜欢
        • 2011-07-21
        • 1970-01-01
        • 1970-01-01
        • 2012-05-10
        • 1970-01-01
        • 2016-06-12
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        相关资源
        最近更新 更多