【问题标题】:CakePHP 1.3 HABTM model PaginationCakePHP 1.3 HABTM 模型分页
【发布时间】:2010-11-15 21:21:17
【问题描述】:

在模型中使用 HABTM 关系而不是在控制器的分页变量中使用 JOIN 时遇到问题,数据输出正常,但我无法将项目的限制设置为 20。

我正在根据项目的特性从数据库中选择项目。

我有一个叫做紧急的功能。

我在紧急列表页面上。

这应该获取所有标记为紧急的项目,并且它做得很好,但它会返回所有结果,而不是我在分页函数中设置的 20 的限制,或者如果我在模型中尝试。这是页面数组代码

$paginate = array(
   'Project' => array(
      'limit' => 20,//works fine when paginating just projects
   ),
   'Feature' => array(
      'limit' => 1, //did set this to 20 but when looking thought well its going to be the limit of the feature table which will only be 1 anyway, notl imit for the projects
      //also tried this below
      'Project' => array(
         'limit' => 20,//no luck with this
      ),
   ),
);

我用它在我的控制器中分页

$this->paginate('Feature', array(..conditions..)); //this brings all my projects marked urgent but I only want 20!

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    您在寻找ContainableBehavior吗?

    $paginate = array(
        'Feature' => array(
            'contain' => array(
                'Project' => array(
                    'limit' => 20,
                    ....
                )
            )
        )
    );
    

    【讨论】:

    • 嗨,谢谢 deceze,我尝试了可控制的行为,但它似乎没有用,但我会再次尝试你的示例,谢谢
    • 天哪,我可以吻你deceze!我重试了这个(因为我之前自己也试过),但后来我认为我没有将可连续 asctsAs 放在特征模型中:D 我这样做了,它奏效了!谢谢!!!!!!
    • deceze,关于如何让它通过分页再次工作的任何想法现在它正在经历 HABTM 关系?谢谢
    • @christopher 使用分页应该可以工作。如果您将其称为 $this->paginate('Model', array(...conditions...)),请注意这些 ...conditions... 会覆盖您在 Controller::$paginate 变量中设置的任何内容。
    • 是的,这就是我使用它的方式..还尝试了我的条件下的自定义 paginationCount 并且不工作:( 嗯...将不得不尝试查找更多信息!谢谢
    【解决方案2】:

    我知道这是一篇有些过时的文章,您正在寻找 1.3 的解决方案,但我在不久前在 1.2 中编写的应用程序中使用了这种技术,它确实有效:Pagination of data from a HABTM relationship

    【讨论】:

    • 嘿,尼克,试过了,但没用,谢谢你的帮助,非常感谢!
    猜你喜欢
    • 2011-06-05
    • 2010-11-30
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多