Routing in Symfony2

前端 未结 10 1672
抹茶落季
抹茶落季 2021-02-05 04:30

How to setup default routing in Symfony2?

In Symfony1 it looked something like this:

homepage:
  url:   /
  param: { module: default, action: index }

de         


        
10条回答
  •  余生分开走
    2021-02-05 05:03

    Symfony2 standard routing component does not support it, but this bundle fills the gap Symfony1 left:

    https://github.com/LeaseWeb/LswDefaultRoutingBundle

    It does what you expect. You can default route a bundle using this syntax:

    FosUserBundle:
      resource: "@FosUserBundle"
      prefix:   /
      type:     default
    

    It scans your bundle and automatically adds routes to your router table that you can debug by executing:

    app/console router:debug
    

    Example of automatically added default routes:

    [router] Current routes
    Name                          Method Pattern
    fos_user.user.login_check     ANY    /user/login_check.{_format}
    fos_user.user.logout          ANY    /user/logout.{_format}
    fos_user.user.login           ANY    /user/login.{_format}
    ...
    

    You see that it also supports the automatic "format" selection by using a file extension (html, json or xml).

提交回复
热议问题