获取在Cakephp中通过分页检索到的记录总数

获取在Cakephp中通过分页检索到的记录总数,php,cakephp,pagination,cakephp-3.0,Php,Cakephp,Pagination,Cakephp 3.0,我想显示查询的记录总数。问题是我正在使用paginator,所以。。只显示页面记录的编号,我需要所有记录的编号 这是我的代码: public function index() { $paisFK = $this -> Auth -> User()['paisFK']; $this->paginate['contain'] = ['Ciudades']; $this->paginate['conditions'] = ['Ciudades.pai

我想显示查询的记录总数。问题是我正在使用paginator,所以。。只显示页面记录的编号,我需要所有记录的编号

这是我的代码:

 public function index()
{
    $paisFK = $this -> Auth -> User()['paisFK'];

    $this->paginate['contain'] = ['Ciudades'];
    $this->paginate['conditions'] = ['Ciudades.paisFK' => $paisFK];

    $complejos = $this->paginate($this->Complejos);

    $this->set(compact('complejos'));
    $this->set('_serialize', ['complejos']);

    //Obtenemos la cantidad de complejos:

    $number = $complejos->count();
    $this->set('number',$number);
}

有人能帮我吗?谢谢

paginator组件使用键
paging
将分页详细信息添加到请求对象参数,其中数据使用表对象的别名嵌套

检查

可以通过paginator helpers
param()
方法在视图模板中轻松访问此数据

$this->Paginator->param('count');
此外,根据您希望如何使用该值,还可以使用自定义格式的
counter()
方法。它支持各种令牌,包括
{{count}

$this->Paginator->counter('There is a total of {{count}} record(s)...');
另见


有一个完整的解决方案,如果您遵循此方法,我认为解决方案如下:

控制器:

public $paginate =[
    'limit' => 10,
    'order' => [
        'tble.id' => 'asc'
    ]
];

public function initialize()
{
    parent::initialize();
    $this->loadComponent('Paginator');
}

public function index()
{
    $product = TableRegistry::get('tble');
    $query = $product->find();
    $this->set(array('data'=>$query));
    $this->set('tble', $this->paginate($query));


    $this->render('index');
}
Index.ctp:

<?= $this->Paginator->prev('<< Previous') ?>
<?= $this->Paginator->next('Next >>') ?>
<?= $this->Paginator->counter() ?>


tble
是数据库表的一个示例。

我正在尝试$number=$this->Paginator->param('count')$此->设置('number',$number);但有一个错误:“错误:调用未定义的方法Cake\Controller\Component\PaginatorComponent::param()”@FederickJons,因为您正在访问控制器中的,而不是视图模板中的。如前所述,
param()
方法属于paginator视图助手,即不需要自己向视图传递任何数据,它将在那里自动可用。
<?= $this->Paginator->prev('<< Previous') ?>
<?= $this->Paginator->next('Next >>') ?>
<?= $this->Paginator->counter() ?>