Closed
Closed
Copy link
Description
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
Labels
DX = Developer eXperience (anything that improves the experience of using Symfony)DX = Developer eXperience (anything that improves the experience of using Symfony)