CakePHP 1.3 HABTM模型分页

时间:2010-11-15 21:21:17

标签: php cakephp

在模型中使用HABTM关系而不是在控制器中的paginate变量中使用JOIN时出现问题,数据很好但我无法将项目限制设置为20。

我正在从数据库中选择依赖于其功能的项目。

我有一个名为紧急的功能。

我正在紧急列表页面上。

这应该获取所有标记为紧急的项目,并且它做得很好,但它会带回所有结果,而不是我在分页功能中设置的20的限制,或者如果我尝试模型。这是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
      ),
   ),
);

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

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

2 个答案:

答案 0 :(得分:2)

您在寻找ContainableBehavior吗?

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

答案 1 :(得分:1)

我知道这是一篇有点过时的文章,你正在寻找一个1.3解决方案,但是我将这种技术用于我在1.2版本中写的应用程序,它确实有效:Pagination of data from a HABTM relationship

相关问题