如何解决错误:在此服务器上找不到请求的地址 - CakePHP [英] How do i resolve Error: The requested address was not found on this server - CakePHP

查看:3628
本文介绍了如何解决错误:在此服务器上找不到请求的地址 - CakePHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用CakePHP 2.X并停留在某一点。



首先让你知道我实现了搜索功能使用form的 POST 方法,但是为此,我发现分页错误。过滤器不会持续到下一页。所以我将form method更改为 GET 。现在它的工作OK (不完全是我需要的,所有请求的数据显示在URL),但现在我在它创建另一个问题的点。



我试图搜索任何东西(DB中的现有数据),并使用分页转到下一页时,我得到了以下错误,现在我更改了搜索关键字与DB不匹配(DB中的数据不存在)


错误:在此服务器上找不到请求的地址


这在POST方法时不存在。

我已经尝试了所有的选项在调试模式 Configure :: write('debug',2) )。但是没有得到任何帮助。



任何人都可以帮助我吗?非常感谢!



感谢。

解决方案

很简单。

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

所以只要捕获控制器中的错误即可。

  public function index(){
try {
$ this-> Paginator-> paginate
} catch(NotFoundException $ e){
//这里做一些操作,比如重定向到第一页或最后一页。
// $ this-> request-> params ['paging']会给你所需的信息。
}
}

这是为什么: http://book.cakephp.org/2.0/ en / core-libraries / components / pagination.html#out-of-range-page-requests


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.

解决方案

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

这篇关于如何解决错误:在此服务器上找不到请求的地址 - CakePHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆