routing.yml中的两条路由?

时间:2014-01-23 11:37:29

标签: symfony routes

我问我们是否要在文件中添加两条路线

因为我有这个错误:

No route found for "GET /blog"

感谢您的帮助

/app/config/routing.yml

rubens_blog:
    resource: "@RubensBlogBundle/Resources/config/routing.yml"
    prefix:   /blog/

rubens_admin:
    resource: "@RubensAdminBundle/Resources/config/routing.yml"
    prefix:   /admin/

/src/Rubens/Bundle/AdminBundle/Resources/config/routing.yml

post_homepage:
    pattern:  /
    defaults: { _controller: RubensAdminBundle:Post:index }

post_archives:
    pattern:  /post/archives
    defaults: { _controller: RubensAdminBundle:Post:archives }

post_show:
    pattern:  /post/show/{id}
    defaults: { _controller: RubensAdminBundle:Post:show }
    requirements:
        id:  \d+

/src/Rubens/Bundle/BlogBu​​ndle/Resources/config/routing.yml

 post_homepage:
    pattern:  /
    defaults: { _controller: RubensBlogBundle:Post:index }

 post_archives:
    pattern:  /archives
    defaults: { _controller: RubensBlogBundle:Post:archives }

2 个答案:

答案 0 :(得分:1)

您错过了/中的尾部斜杠/blog。尝试在浏览器中打开下一页:

/blog/

或删除前缀:

rubens_blog:
    resource: "@RubensBlogBundle/Resources/config/routing.yml"
    prefix:   /

并将路线更改为:

post_homepage:
    pattern:  /blog
    defaults: { _controller: RubensAdminBundle:Post:index }

post_archives:
    pattern:  /blog/post/archives
    defaults: { _controller: RubensAdminBundle:Post:archives }

post_show:
    pattern:  /blog/post/show/{id}
    defaults: { _controller: RubensAdminBundle:Post:show }
    requirements:
        id:  \d+

答案 1 :(得分:0)

您重新定义了路线名称。您的名字必须是唯一的:

rubens_blog:
    resource: "@RubensBlogBundle/Resources/config/routing.yml"
    prefix:   /blog/

rubens_admin:
    resource: "@RubensAdminBundle/Resources/config/routing.yml"
    prefix:   /admin/

/src/Rubens/Bundle/AdminBundle/Resources/config/routing.yml

admin_post_homepage:
    pattern:  /
    defaults: { _controller: RubensAdminBundle:Post:index }

admin_post_archives:
    pattern:  /post/archives
    defaults: { _controller: RubensAdminBundle:Post:archives }
admin_post_show:
    pattern:  /post/show/{id}
    defaults: { _controller: RubensAdminBundle:Post:show }
    requirements:
        id:  \d+

/src/Rubens/Bundle/BlogBu​​ndle/Resources/config/routing.yml

 blog_post_homepage:
    pattern:  /
    defaults: { _controller: RubensBlogBundle:Post:index }

 blog_post_archives:
    pattern:  /archives
    defaults: { _controller: RubensBlogBundle:Post:archives }