How do i resolve Error: The requested address was not found on this server - CakePHP

半腔热情 提交于 2019-12-24 03:12:39

问题


I'm using CakePHP 2.X in my project and stuck at one point.

First of all let you know that i implemented search functionality using form's POST Method, But for this i found error in pagination. Filter will not sustain for next page. So i changed form method to GET. now its working OK ( Not exactly what i required, All requested data displaying in URL ), but now i'm at the point where its create another issue.

I got below error when i trying to search anything ( Existing data in DB ), and go to next page using pagination, now i changed search keyword with not matched in DB ( Data Not Exist in DB ).

Error: The requested address was not found on this server

Which was not there at the time of POST method.

I have tried with all the option in debug mode (Configure::write('debug', 2)). but not getting any help from it.

Can anyone help me out from this? It will be really appreciated!

Thanks.


回答1:


The answer is simple.

lib/Cake/Controller/PaginatorComponent.php
if ($requestedPage > $page) { 
        throw new NotFoundException();
}

So just catch the error in your controller.

public function index() {
    try {
        $this->Paginator->paginate();
    } catch (NotFoundException $e) {
        //Do something here like redirecting to first or last page.
        //$this->request->params['paging'] will give you required info.
    }
}

This is why: http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#out-of-range-page-requests



来源:https://stackoverflow.com/questions/20904279/how-do-i-resolve-error-the-requested-address-was-not-found-on-this-server-cak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!