CakePHP 2 pagination gives 404 address not found error -


i developing application cakephp 2.3 , having problem pagination. when click on of pagination links getting /cab/servicedirectory/refine/page:2 (or ever link) not found on server. if go /cab/servicedirectory/refine see pagination links showing there should 5 pages. if remove pagination code controller , view see results should see.

in servicedirectoryresultscontroller have

public function index() {   $this->servicelocation->recursive=0; }  public function refine ($id=null) (   // code servicelocations db  $this->paginate->array(   'conditions' => array('servicelocation.state' => $states[$state], 'servicelocation.solution_categories' => $active_cat),   'limit' => 8, );  $results = $this->paginate('servicelocation'); $this->set('servicelocation' ,$results);  } 

in view have

<div class="paging">   <?php     echo $this->paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));     echo $this->paginator->numbers(array('separator' => ''));     echo $this->paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));   ?> </div>  <?php foreach ($servicelocation $location): ?>    // echo few things $location array  <?php endforeach; ?>  <div class="paging">   <?php     echo $this->paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));     echo $this->paginator->numbers(array('separator' => ''));     echo $this->paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));   ?> </div> 

without paging , use doing find , sending view see 40 results expect.

with pagination in see pagination links , if hover on them see url /cab/servicedirectoryresults/refine/page:2 or page:3 or page:4 or page:5

if click on of these links :pagex on them error

error: requested address '/cab/servicedirectoryresults/refine/page:2 not found on server'

i have done lot of reading cakephp paging , can not find reason behaviour. can suggest reason or possible solution or path follow debug error?

regards

richard

i checked error level , set level 2

here last entry in error log

2013-05-22 17:09:28 error: [notfoundexception] not found request url: /cab/servicedirectoryresults/refine/page:2 stack trace: #0 /var/www/html/cab/lib/cake/controller/controller.php(1074): paginatorcomponent->paginate('servicelocation', array, array) #1 /var/www/html/cab/app/controller/servicedirectoryresultscontroller.php(381): controller->paginate('servicelocation') #2 [internal function]: servicedirectoryresultscontroller->refine() #3 /var/www/html/cab/lib/cake/controller/controller.php(486): reflectionmethod->invokeargs(object(servicedirectoryresultscontroller), array) #4 /var/www/html/cab/lib/cake/routing/dispatcher.php(187): controller->invokeaction(object(cakerequest)) #5 /var/www/html/cab/lib/cake/routing/dispatcher.php(162): dispatcher->_invoke(object(servicedirectoryresultscontroller), object(cakerequest), object(cakeresponse)) #6 /var/www/html/cab/app/webroot/index.php(109): dispatcher-   >dispatch(object(cakerequest), object(cakeresponse)) #7 {main} 

hope helps

fyi: i'm using cakephp 2.4, i've tested on version.

i ran same issue. store pagination variables in user's session.
way when user navigates away page, don't loose place (page/sort field/direction) when come page.

because store variables in session, retrieve them session, if user clicks on link causes results less page on, i'll 404.

example (the page on):
http://localhost/products/index/page:5/sort:product.name

i send them link:
http://localhost/products/index/search:[search_term]

this filters results 2 pages.
in case, actual (perma)link, session variables restored, like:
http://localhost/products/index/page:5/sort:product.name/search:[search_term]

page 5 out of scope of 2 pages new results.
throw notfoundexception(); seen here:
http://api.cakephp.org/2.4/source-class-paginatorcomponent.html#238

how resolved catch exception, redirect them first page. since of pagination variables (including 'search') stored in session, need pass page variable:

example:
http://localhost/products/index/page:1

cakephp recommended possible way overcome it:
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#out-of-range-page-requests

however, wanted available of 'index' pages, overwrote controller::paginate() method in appcontroller.
original paginate method seen here:
http://api.cakephp.org/2.4/source-class-controller.html#1070-1081

here how did in controller/appcontroller.php:

<?php  class commonappcontroller extends controller {     // ..... other code     public function paginate($object = null, $scope = array(), $whitelist = array())     {     /*      * used see if exception thrown,       * if so, send them first page, , set flash know      */         try         {             // taken current paginate();             // http://api.cakephp.org/2.4/source-class-controller.html#1070-1081             return $this->components->load('paginator', $this->paginate)->paginate($object, $scope, $whitelist);         }         catch (notfoundexception $e)         {             //do here redirecting first or last page.             //$this->request->params['paging'] give required info.             $page = (isset($this->request->params['named']['page'])?$this->request->params['named']['page']:1);              $this->session->setflash(__('unable find results on page: %s. redirected page 1.', $page));             return $this->redirect(array('page' => 1));         }     }     // ..... other code } ?> 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

php - Dynamic url re-writing using htaccess -

java - Multi-Label Document Classification -