Skip to content

[DX][FrameworkBundle] Simpler route configuration for templates and redirections  #24640

Closed
@javiereguiluz

Description

@javiereguiluz

Context

In #23227 we made this change:

# BEFORE ----------------------------------------------------------------------
blog_show:
    path:     /blog/{slug}
    defaults: { _controller: App\Controller\BlogController::showAction }

# AFTER -----------------------------------------------------------------------
blog_show:
    path:       /blog/{slug}
    controller: App\Controller\BlogController::showAction

In #24637 we improved a bit the routes that render a template directly, but I don't think that's enough.

Proposal

Let's finish #23227 by adding shortcuts for templates and redirections:

Templates

# BEFORE ----------------------------------------------------------------------
blog_show:
    path:     /blog/{slug}
    defaults:
        _controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
        template: blog/show.html.twig

# AFTER -----------------------------------------------------------------------
blog_show:
    path:     /blog/{slug}
    template: blog/show.html.twig

Redirections

If the value of redirect_to starts with / or // or http:// or https://, it's considered a URL redirect. Otherwise, it's a route redirect:

# BEFORE ----------------------------------------------------------------------
blog_show:
    path:     /blog/{slug}
    defaults:
        _controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction
        path: /some-relative-url
        permanent: true

# AFTER -----------------------------------------------------------------------
blog_show:
    path:        /blog/{slug}
    redirect_to: /some-relative-url
    permanent:   true
# BEFORE ----------------------------------------------------------------------
blog_show:
    path:     /blog/{slug}
    defaults:
        _controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
        route: some-other-route

# AFTER -----------------------------------------------------------------------
blog_show:
    path:        /blog/{slug}
    redirect_to: some-other-route

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions