Redirection in symfony

综合编程 2018-05-24

I'm trying to understand if there is any difference between these two ways to do a redirection in symfony.

1 Via config without custom controller

As explained here
.

# app/config/routing.yml

# ...

codes:
    path: /codes # redirect /codes to /code
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /code
        permanent: true

2 Via redirect() method in a custom controller

As explained here
.

class RedirectsController extends Controller {
    /**
     * @Route("/codes")
     */
    public function codesAction() {
        return $this->redirect('/code', 301); // redirect /codes to /code
    }
}

When I talk about differences I mean things like performance, ease of use and maintainability.

Thanks.

In the first case you don't need to create a controller. You can manage everything from the configuration, and this is a convenience. The redirect will be made by RedirectController
. In terms of performance there is no difference between the two methods.

If what you have to do is redirect then go with the first method.

Hello, buddy!

责编内容by:Hello, buddy! (源链)。感谢您的支持!

您可能感兴趣的

A week of symfony #576 (8-14 January 2018) This week, Symfony announced theend of Silex, the end of the Symfony Standard Edition and the end of the Symfony Installer becauseSymfony 4 mak...
Asmir Mustafic: How do I deploy my Symfony API ... Asmir Mustafic has finished out his series showing his method for the deployment of Symfony applications with part five sharing some additiona...
PHP-PM 1.0 launches with Docker images and Symfony... Running an application server written in PHP has been feasible for some years. One of the robus mature options for this has been PHP-PM, a process man...
Matthew Setter: First Experiences with Symfony 4 &... Matthew Setter has a new post to his site sharing some of his experiences and interactions with Symfony 4 and it's community as someone new to...
A week of symfony #547 (19-25 June 2017) This week, Symfony focused on fixing minor issues across all the supported branches. Meanwhile, the upcoming 3.4 version added a new validator ...