php request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 没有找到“GET /”的路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11932756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:29:29  来源:igfitidea点击:

request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /"

phpsymfony

提问by Homunculus Reticulli

I have installed Symfony2, after fixing the file permissions, I can access the dev environment from my browser by pointing it to:

我已经安装了 Symfony2,在修复文件权限后,我可以通过将其指向以下内容从浏览器访问开发环境:

http://localhost/app_dev.php

http://localhost/app_dev.php

However, when I try to access the production environment by pointing the browser to http://localhost, I get the following exception (from app/logs/prod.log):

但是,当我尝试通过将浏览器指向 来访问生产环境时,http://localhost出现以下异常(来自 app/logs/prod.log):

[2012-08-13 11:30:03] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /" (uncaught exc eption) at /path/to/frameworks/Symfony2/app/cache/prod/classes.php line 4584 [] []

[2012-08-13 11:30:03] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 在 /path/to/frameworks/Symfony2/app 找不到“GET /”(未捕获的异常)的路由/cache/prod/classes.php 行 4584 [] []

I then checked the available routes for the prod environment from the command line. here is the result of that investigation.

然后我从命令行检查了 prod 环境的可用路由。这是调查的结果。

root@yourbox:~/path/to/frameworks/Symfony2$ php app/console router:debug -e=prod [router] Current routes Name Method Pattern

root@yourbox:~/path/to/frameworks/Symfony2$ php app/console router:debug -e=prod [router] 当前路由名称方法模式

Incredibly, it shows that there are no routes defined for this environment (I didn't believe the error message - which essentially said the same thing).

令人难以置信的是,它表明没有为此环境定义路由(我不相信错误消息 - 基本上说的是同一件事)。

So, my conclusion is this: out of the box installation of Symfony2, and the production environment has no default routes - is this true, or have I made a mistake somewhere?

所以,我的结论是:开箱即用的 Symfony2 安装,并且生产环境没有默认路由——这是真的,还是我在某处犯了错误?

More importantly, how do I fix this?. In SF1.x, it was straight forward to switch from dev to prod and vice versa. How do I view the AcmeDemoapp for example, in a prod environment. ?

更重要的是,我该如何解决这个问题?在 SF1.x 中,可以直接从 dev 切换到 prod,反之亦然。AcmeDemo例如,如何在生产环境中查看应用程序。?

[[UPDATE]]

[[更新]]

After feedback from thecatontheflat, I added a simple test route to my routing.yml file. The contents of app/config/routing.yml are now:

在得到thecatontheflat 的反馈后,我在我的 routing.yml 文件中添加了一个简单的测试路由。app/config/routing.yml 的内容现在是:

_welcome2:
    pattern:  /test
    defaults: { _controller: AcmeDemoBundle:Welcome:index }

When I try http://localhost/testin the browser, I get the same 404 error. When I debug the routes available at the console, I get the following output:

当我http://localhost/test在浏览器中尝试时,我收到相同的 404 错误。当我调试控制台上可用的路由时,我得到以下输出:

root@yourbox:~/path/to/frameworks/Symfony2$ php app/console router:debug -e=prod
[router] Current routes
Name      Method Pattern
_welcome2 ANY    /test

采纳答案by Dr.V

I had the exact same problem!!

我有同样的问题!!

Symfony2 has two generic routing files called:

Symfony2 有两个通用路由文件,称为:

app/config/routing.yml and app/config/routing_dev.yml

However, it also has a bundle specific routing file in each bundle. The standard procedure is to define all of your bundle routes in your bundle routing.yml file then reference this from the main routing.yml file by adding:

但是,它在每个包中也有一个包特定的路由文件。标准过程是在您的 bundle routing.yml 文件中定义所有的 bundle 路由,然后通过添加从主 routing.yml 文件中引用它:

YourbundlenameMainBundle:

resource: "@YourbundlenameMainBundle/Resources/config/routing.yml"

prefix:   /

This is what I had and I was still getting the error. But then I read the error more closely... no route found for GET / .... then I checked my routing_dev.yml file and of course it had a route for / from the Acme demo bundle _welcome route. This is why it works for the dev version but not the prod version!

这就是我所拥有的,但我仍然收到错误消息。但是后来我更仔细地阅读了错误……没有找到 GET / 的路由……然后我检查了我的 routing_dev.yml 文件,当然它有一个来自 Acme 演示包 _welcome 路由的路由。这就是为什么它适用于开发版本而不适用于生产版本!

Solution:

解决方案:

Add a route for / to either your routing.yml global file or your routing.yml bundle file by adding the following:

通过添加以下内容,将 / 的路由添加到routing.yml 全局文件或routing.yml 包文件:

_welcome:

pattern:  /

defaults: { _controller: YourbundlenameMainBundle:Default:index }

you can change index to some other route if your welcome page is not index

如果您的欢迎页面不是索引,您可以将索引更改为其他路由

回答by Stelian

After you make sure you have your / route defined in any of your routing.yml

确保在任何 routing.yml 中定义了 / 路由之后

_welcome:
pattern:  /
defaults: { _controller: YourbundlenameMainBundle:Default:index }

clear your prod environment cache!

清除您的产品环境缓存!

app/console cache:clear --env=prod

回答by Paul van der Veen

I had the exact same problem. And it was caused because of a missing bundel in the AppKernel.php.

我有同样的问题。这是由于 AppKernel.php 中缺少 bundle 造成的。

A little late but you might try to change this line in the web/app.php: $kernel = new AppKernel('prod', false); to: $kernel = new AppKernel('prod', true);

有点晚了,但您可能会尝试更改 web/app.php 中的这一行: $kernel = new AppKernel('prod', false); 到: $kernel = new AppKernel('prod', true);

That will enable debugging and you should be able to find your problem. When fixed you will ofcorse need to change it back to false ;).

这将启用调试,您应该能够找到您的问题。修复后,您将 ofcorse 需要将其改回 false ;)。

Hope this helps.

希望这可以帮助。