在cakephp中显示分页项目的最后一页

时间:2014-07-28 07:47:22

标签: php cakephp pagination

如果请求页面在cakephp中的表的分页项中说第3页, 只有2页,我们如何显示最后一页,即第2页?

1 个答案:

答案 0 :(得分:0)

我在这里找到了解决方案: -

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
        }
    }
}