简体   繁体   English

Symfony2无法找到路径的控制器

[英]Symfony2 Unable to find the controller for path

All of my research on this problem lead me to nothing : 我对这个问题的所有研究都使我一无所获:

I still have this error : Unable to find the controller for path "/blog/1". 我仍然遇到此错误: 无法找到路径“ / blog / 1”的控制器。 Maybe you forgot to add the matching route in your routing configuration? 也许您忘了在路由配置中添加匹配的路由? , every time with this route for BlogBundle ,每次使用BlogBu​​ndle的这条路线

blog_index:
    path:    /{page}
    defaults: { _controller: PathBlogBundle:Blog:index, page: 1 }
    requirements:
        page:  "\d*"
        _method:  GET

blog_see:
    path:    /article/{id}
    defaults: { _controller: PathBlogBundle:Blog:voir }
    requirements:
        id:  "\d+"
        _method:  GET

blog_add:
    path:    /add
    defaults: { _controller: PathBlogBundle:Blog:ajouter }
    requirements:
        _method:  POST

blog_update:
    path:    /update/{id}
    defaults: { _controller: PathBlogBundle:Blog:modifier }
    requirements:
        id:  "\d+"
        _method:  GET

blog_delete:
    path:    /delete/{id}
    defaults: { _controller: PathBlogBundle:Blog:supprimer }
    requirements:
        id:  "\d+"
        _method:  GET

And here is the app one : 这是应用程序之一:

default:
    resource: "@PathBlogBundle/Resources/config/routing.yml"
    prefix:    /

path:
    resource: "@PathBlogBundle/Resources/config/routing.yml"
    prefix:    /blog

Your problem most likely lies in the app/config/config.yml file. 您的问题很可能出在app / config / config.yml文件中。 You seem to be having two different configurations pointing to the same resource instead of one. 您似乎有两个指向同一资源的不同配置,而不是一个。

default:
    resource: "@PathBlogBundle/Resources/config/routing.yml"
    prefix:    /

DagomaBlogBundle:
    resource: "@PathBlogBundle/Resources/config/routing.yml"
    prefix:    /blog

Symfony looks at the first configuration, that is Symfony查看第一个配置,即

default:
    resource: "@PathBlogBundle/Resources/config/routing.yml"
    prefix:    /

try deleting the configuration with prefix path / and refresh. 尝试删除带有前缀路径/的配置,然后刷新。

In app/config/routing.yml comment out the imported routing files(for testing). app/config/routing.yml注释掉导入的路由文件(用于测试)。 Add this: 添加:

blog_index:
    path:    /blog/{page}
    defaults: { _controller: PathBlogBundle:Blog:index, page: 1 }
    requirements:
        page:  \d+
        _method:  GET

If this works, then you know that the problem lies with how you are importing the yml files. 如果这行得通,那么您就知道问题出在如何导入yml文件。 If this doesn't work, then there must be a deeper issue somewhere. 如果这不起作用,那么某个地方肯定存在更深层次的问题。

UPDATE: 更新:

add the following in app/config/routing.yml app/config/routing.yml添加以下内容

path:
    resource: "@PathBlogBundle/Resources/config/routing.yml"
    prefix:    /blog

通过删除路线中{}附近的多余空格来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM