如何在Cakephp中进行多页分页而不出现page not found错误

如何在Cakephp中进行多页分页而不出现page not found错误,cakephp,pagination,paginator,Cakephp,Pagination,Paginator,我在学生模型视图页面中对2个模型(收入、支出)进行了分页。 我真的没有发现cakephp分页的问题 当分页结果只有1页或相同页时没有任何问题,但如果其中一页的分页结果多于另一页,则会出错 for example. -income has paginate result 1 page and expanse has 1 page. No problem at all. -income has 10 pages and expanse has 10 pages no problem at all.

我在学生模型视图页面中对2个模型(收入、支出)进行了分页。 我真的没有发现cakephp分页的问题

当分页结果只有1页或相同页时没有任何问题,但如果其中一页的分页结果多于另一页,则会出错

for example.
-income has paginate result 1 page and expanse has 1 page. No problem at all.
-income has 10 pages and expanse has 10 pages no problem at all.
-income has 2 pages and expanse has 1 page. income page 2 page not found error.
-income has 5 pages and expanse has 2 pages. income page 3,4,5 page not found error.
-income has 10 pages and expanse has 13 pages. expanse page 11,12,13 page not found error.
例如(不是真实的),学生视图包含收入和支出项目,两者都显示为分页

//this is how I config paginator in Student controller.
public $paginate = array(
    'Income' => array (
            'order'=>array('income_id'=>'ASC'),
            'limit'=>10,
            'recursive'=>0  
    ),
    'Expense' => array (
            'order'=>array('expense_id'=>'ASC'),
            'limit'=>10,
            'recursive'=>0,

    )
);


<div class="paging">//this is how I config Income paginator in Student view
    <?php
        echo $this->Paginator->prev('< ' . __('previous'), array('model'=>'Income'), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('model'=>'Income','separator' => '','modulus'=>100,'first'=>'หน้าแรก','last'=>'หน้าสุดท้าย'));
        echo $this->Paginator->next(__('next') . ' >', array('model'=>'Income'), null, array('class' => 'next disabled'));
    ?>
    </div>


//this is how I config Expanse paginator in Student view
    <div class="paging">
    <?php
        echo $this->Paginator->prev('< ' . __('previous'), array('model'=>'Expanse'), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('model'=>'Expanse','separator' => '','modulus'=>100,'first'=>'หน้าแรก','last'=>'หน้าสุดท้าย'));
        echo $this->Paginator->next(__('next') . ' >', array('model'=>'Expanse'), null, array('class' => 'next disabled'));
    ?>
    </div>
//这是我在学生控制器中配置分页器的方式。
public$paginate=数组(
“收入”=>数组(
'order'=>array('income\u id'=>'ASC'),
“限制”=>10,
“递归”=>0
),
“费用”=>数组(
'order'=>array('expense\u id'=>'ASC'),
“限制”=>10,
“递归”=>0,
)
);
//这是我在学生视图中配置收入分页器的方式
//这是我在学生视图中配置扩展分页器的方式
请帮帮我。对不起,我的英语不好 如果你有任何问题,请问我。
谢谢。

我认为如果您使用两个不同的iFrame加载不同的URL进行分页,您可以处理这个问题。
或者,您必须调用ajax函数在一个页面中分页2个模型,而无需重新加载页面….

是的,这是可能的

步骤1:在View/Elements/paging.ctp中创建paging.ctp

<?php if (!isset($this->Paginator->params['paging'])) {
  return;
}
if (!isset($model) || $this->Paginator->params['paging'][$model]['pageCount'] < 2) {
  return;
}
if (!isset($options)) {
  $options = array();
}
$options['model'] = $model;
$options['url']['model'] = $model;
$this->Paginator->__defaultModel = $model;

?>
<div class="paging">
  <ul class="pagination pull-right">
    <?php
        echo $this->Paginator->prev('<<', array_merge(array('class' => '', 'tag' => 'li'), $options), null, array('class' => 'disabled', 'tag' => 'li'));
        echo $this->Paginator->numbers(am($options,array('tag' => 'li', 'separator' => '', 'currentClass' => 'active', 'currentTag' => 'a')));
        echo $this->Paginator->next('>>', array_merge(array('class' => '', 'tag' => 'li'), $options), null, array('class' => 'disabled', 'tag' => 'li'));
    ?>
  </ul>

</div>
步骤3:现在在控制器操作中,执行一些条件,以便调用正确的页面

if (empty($this->request->params['named'])) {
$page = $this->pageForPagination('Income');
$page1 = $this->pageForPagination('Expense');
public $paginate = array(
    'Income' => array (
            'order'=>array('income_id'=>'ASC'),
            'limit'=>10,
            'page' => $page,
            'recursive'=>0  
    ),
    'Expense' => array (
            'order'=>array('expense_id'=>'ASC'),
            'limit'=>10,
            'page' => $page1,
            'recursive'=>0,

    ));
} else if ($this->request->params['named']['model'] == 'Income') {
$page = $this->pageForPagination('Income');
public $paginate = array(
    'Income' => array (
            'order'=>array('income_id'=>'ASC'),
            'limit'=>10,
            'page' => $page,
            'recursive'=>0  

));
} else if ($this->request->params['named']['model'] == 'Expense') {
$page1 = $this->pageForPagination('Expense');
public $paginate = array(
    'Expense' => array (
            'order'=>array('income_id'=>'ASC'),
            'limit'=>10,
            'page' => $page1,
            'recursive'=>0  

  ));
步骤4:现在在学生视图中调用分页元素

<?php echo $this->element('paging', array('model' => 'Income'));?>
 <?php echo $this->element('paging', array('model' => 'Expense'));?>

注意:请注意括号和分号……。抱歉迟到,但会帮助其他人……谢谢

<?php echo $this->element('paging', array('model' => 'Income'));?>
 <?php echo $this->element('paging', array('model' => 'Expense'));?>