Symfony2我尝试运行时找不到“ get /”的路线 http://localhost/app_dev.php, ,但此URL有效: http://localhost/app_dev.php/hello/symfony. 。我删除了Acmedemobundle,我正在尝试从Symfony2教程中运行一个示例捆绑包。怎么了 ?

app/config/routing.yml:

ShopMyShopBundle:
resource: "@ShopMyShopBundle/Resources/config/routing.yml"
prefix:   /

app/config/routing_dev.yml:

_assetic:
resource: .
type:     assetic

_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix:   /_wdt

_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix:   /_profiler

_configurator:
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix:   /_configurator

_main:
resource: routing.yml

src/shop/myshopbundle/resources/config/routing.yml:

ShopMyShopBundle_homepage:
pattern:  /hello/{name}
defaults: { _controller: ShopMyShopBundle:Main:index }
requirements:
    _method:  GET
有帮助吗?

解决方案

问题是您没有 /. 。更改您的定义:

ShopMyShopBundle_homepage:
    pattern:  /
    defaults: { _controller: ShopMyShopBundle:Main:index }
    requirements:
        _method:  GET

其他提示

以上答案分别是错误的,分别没有回答为什么您在查看演示范围的产品模式时遇到麻烦。

这是正确的答案:清除您的“ prod” -cache:

php app/console cache:clear --env prod

这项工作给我:

cache:clear --env=prod

将Symfony 2.3与PHP 5.5一起使用,并将内置服务器与

app/console server:run

应该输出类似的东西:

Server running on http://127.0.0.1:8000
Quit the server with CONTROL-C.

然后去 http://127.0.0.1:8000/app_dev.php/app/example

这应该给您默认值,您还可以通过查看src/appbundle/controller/defaultcontroller.php来找到默认路由

前缀是URL路由的前缀。如果它等于“/”,则意味着它将没有前缀。然后,您定义了一条图案“应该以 /Hello开头”的路线。

要创建“/'”路由,您需要在src/shop/myShopbundle/resources/config/config/routing.yml中添加这些行:

ShopMyShopBundle_homepage:
    pattern:  /
    defaults: { _controller: ShopMyShopBundle:Main:index }

我本来只有一个犯了这个错误的人,但也许不是这样,我会发布。

注释格式 在一条路线之前的评论中,必须从斜线开始 星号。我犯了一个斜线的错误,只有一个星号,phpstorm自动完成。

我的路线看起来像:

/*
 * @Route("/",name="homepage")
 */
public function indexAction(Request $request) {
    return $this->render('default/index.html.twig');
}

当应该是这个

/**
 * @Route("/",name="homepage")
 */
public function indexAction(Request $request) {
    return $this->render('default/base.html.twig');
}

我也尝试了这个错误,我只添加/hello/hello nose nose n hello/hello n hello/hello n hello/hello hello

示例:不仅仅是放置 http://localhost/app_dev.php

这样说 http://localhost/name_of_your_project/web/app_dev.php/hello/ai

它将显示Hello AI。我希望我回答你的问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top