How to do multiple pagination without page not found error in Cakephp -


i have paginate 2 models (income,expanse) in student model view page . have page not found problem cakephp's pagination.

it have no problem when paginate result has 1 page or same, error if 1 has more paginate result other.

for example. -income has paginate result 1 page , expanse has 1 page. no problem @ all. -income has 10 pages , expanse has 10 pages no problem @ all. -income has 2 pages , expanse has 1 page. income page 2 page not found error. -income has 5 pages , expanse has 2 pages. income page 3,4,5 page not found error. -income has 10 pages , expanse has 13 pages. expanse page 11,12,13 page not found error. 

for example(not real one) , student's view have income , expense items ,both display pagination.

//this how 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 how 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 how 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> 

please me. sorry english if have question , please ask me. thank you.

yes possible.....

step1 : make paging.ctp in view/elements/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> 

step2: add function controllers/appcontroller

public function pageforpagination($model) {         $page = 1;          $samemodel = isset($this->request->params['named']['model']) && $this->request->params['named']['model'] == $model;         $pageinurl = isset($this->request->params['named']['page']);         if ($samemodel && $pageinurl) {             $page = $this->request->params['named']['page'];         }          $this->passedargs['page'] = $page;         return $page;     } 

step3: in controller action conditions proper page should call

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

step 4: call paging element in student view

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

note: please take care of brackets , semicolon.......and sorry late others...thanks..


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -