0

If requesting for a page say page number 3 in paginated items of a table in cakephp, which is having only 2 pages, how do we show the last page ie page number 2?

Varada
  • 16,026
  • 13
  • 48
  • 69

1 Answers1

0

I found out the solution here:-

cakephp paginator helper shows error when delete the last record from the last page

public function index() {
    try {
        $paginatedData = $this->Paginator->paginate();
    } catch (NotFoundException $e) {
        //get current page
        $page = $this->request->params['named']['page'];
        if( $page > 1 ){
            //redirect to previous page
            $this->redirect( array( "page" => $page-1 ) );
        }else{
            $paginatedData = array(); //no data to paginate so use empty array()
                                      //you will have to check for this in the view and no longer display the pagination links, since they will NOT be defined
        }
    }
}
Community
  • 1
  • 1
Varada
  • 16,026
  • 13
  • 48
  • 69