【问题标题】:Paginate component fetches all data not paged data分页组件获取所有数据而不是分页数据
【发布时间】:2013-04-29 02:29:30
【问题描述】:

我有一个模型,我想对其数据进行分页。我所做的就是,创建一个模型,像这样,

class MyModel extends AppModel {}

并在我的控制器中包含 Paginator 组件并使用它,就像这样,

class MyControllers extends AppController
{
public $components = array('Paginator');

public function index()
{
$this->paginate['MyModel'] = array('limit'=>5);
print_r($this->paginate('MyModel'));
}
}

我有一个名为 my_controllers 的表,它有 10 条记录。如果一切正常,分页器组件必须为我提供第一页的 5 条记录和第 2 页的 5 条记录。但它给了我 10 条记录而没有任何分页。

有什么问题? :(

谢谢

【问题讨论】:

  • 我在这段代码中没有发现问题(虽然还没有测试过)。但是,这可能 not 您的 actual 代码,我真的建议您也添加 actual 代码的相关部分,作为问题可能在该代码的某个地方。您可以通过单击edit 链接将其添加到您的问题中

标签: cakephp cakephp-2.3


【解决方案1】:

在你的控制器中试试这个:

public function index() {
  $this->paginate = array('limit'=>5);
  $this->set('yourVariableNameHere', $this->paginate());
}

【讨论】:

  • 谢谢,非常感谢。谢谢你,先生。你解决了我的问题。谢谢你。我不知道为什么$paginate 属性不起作用!如果我按照您所说的那样即时设置$property,则分页将正常工作。为什么?
猜你喜欢
  • 2020-11-23
  • 1970-01-01
  • 1970-01-01
  • 2015-01-14
  • 2012-06-01
  • 2016-12-16
  • 1970-01-01
  • 2021-02-09
  • 1970-01-01
相关资源
最近更新 更多