Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@javiereguiluz

Description

@javiereguiluz
Issue body actions

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)DX = 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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.