Routing in Symfony2

前端 未结 10 1667
抹茶落季
抹茶落季 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 04:56

    I was looking through the cookbook for an answer to this, and think I've found it here. By default, all route parameters have a hidden requirement that they match any character except the / character ([^/]+), but this behaviour can be overridden with the requirements keyword, by forcing it to match any character.

    The following should create a default route that catches all others - and as such, should come last in your routing config, as any following routes will never match. To ensure it matches "/" as well, a default value for the url parameter is included.

    default_route:
        pattern: /{url}
        defaults: { _controller: AcmeBundle:Default:index, url: "index" }
        requirements:
            url: ".+"
    

提交回复
热议问题