简体   繁体   中英

Symfony2 Routing: how to don't omit default parameters automatically

If I define a route like this one:

search:
    path:     /search/{country}/{xxx}-3-{xxxId}/{page}/{limit}
    defaults: 
        _controller: SearchBundle:Search:index
        page: 0
        limit: 8

it will omit the {page} and {limit}-Parameters if they are passed with their default parameters.

Building a route with page=2 and limit=4 will return

/search/country/xxx-3-xxxId/2/4

But when {limit} is passed with 8, it will return

/search/country/xxx-3-xxxId/2

instead of

/search/country/xxx-3-xxxId/2/8

Is their a way to prevent, that parameters are omitted automatically if they equals their defined defaults?

You can define many routes to the same action:

search_main:
    path: /search/{country}/{xxx}-3-{xxxId}
    defaults: 
        _controller: SearchBundle:Search:index

search:
    path: /search/{country}/{xxx}-3-{xxxId}/{page}/{limit}
    defaults: 
        _controller: SearchBundle:Search:index

CONTROLLER:

public function indexAction($country, $xxx, $xxxId, $page = 0, $limit = 8)
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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