Skip to content

Accessing route options #11171

Closed
Closed
@sprain

Description

@sprain

Routes can have additional options, like this:

some_route:
    pattern:  /my/nice/pattern
    defaults: { _controller: MyBundle:MyController:MyAction }
    options:
      foo: 'bar'

To access routing options in a controller you need to call $this->get('router')->getRouteCollection()->get($routeName)->getOptions(). However, getRouteCollection() is a very expensive call and destroys all route caching advantages, even in prod env.

It is not clear for a developer that routing options are not meant to be used in a controller. The only place this is mentioned seems to be in #4436.

There should be either 1) a more efficient way to access route options or 2) a clearer best practice guide on what route options are meant to be used for and what the alternatives are.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions