简体   繁体   English

CakePHP 1.3 HABTM模型分页

[英]CakePHP 1.3 HABTM model Pagination

Have been having an issue sine using the HABTM relationship in models instead of using a JOIN in the paginate variable in the controller, data comes out fine but I can't set the limit of projects to 20. 在模型中使用HABTM关系而不是在控制器的paginate变量中使用JOIN一直存在问题,数据很好,但我不能将项目限制设置为20。

I am selecting projects from the DB depeneding on their features. 我从数据库中选择依赖于其功能的项目。

I havea feature called urgent. 我有一个叫做紧急的功能。

I'm on the urgent listing page. 我在紧急列表页面上。

this should fetch all projects marked with urgent, and it does this fine but it brings back all the results instead of the limit of 20 I set in the paginate function or if I try in the models. 这应该获取所有标记为紧急的项目,它可以很好地完成工作,但它会带回所有结果,而不是我在分页函数或模型中设置的20个限制。 here's the pagien array code 这是pagien数组代码

$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
      ),
   ),
);

I use this to paginate in my controller 我用它在我的控制器中分页

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

Are you looking for the ContainableBehavior ? 您是否正在寻找ContainableBehavior

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

我知道这是一篇过时的文章,并且您正在寻找一种1.3解决方案,但是我将这种技术用于我在1.2 年前编写的应用程序中,并且绝对有效: 从HABTM关系分页数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM