如何修复Symfony 3.4 @Route和@Method弃用

Str*_*bek 2 routing symfony deprecation-warning symfony-3.4

我有一个Symfony 3.4项目,我在profiler中找到了以下消息:

  1. 从版本5.2开始,不推荐使用"Sensio\Bundle\FrameworkExtraBundle\Configuration\Route"注释.使用"Symfony\Component\Routing\Annotation\Route"
  2. 从版本5.2开始,不推荐使用"Sensio\Bundle\FrameworkExtraBundle\Configuration\Method"注释.使用"Symfony\Component\Routing\Annotation\Route"
  3. 自版本5.2起,不推荐使用"sensio_framework_extra.router.annotations"配置.将其设置为false并使用"Symfony\Component\Routing\Annotation\Route"

我花了一些时间寻找解决方案,但没有发现任何真正有用的东西.一些发现在这里这里.

Eri*_*son 10

替换这个:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

class UserController
    {
    /**
     * @Route("/users")
     * @Method("GET")
     */
    public action index()
        {}
Run Code Online (Sandbox Code Playgroud)

有了这个:

use Symfony\Component\Routing\Annotation\Route;
class UserController
    {
    /**
     * @Route(path="/users", methods={"GET"})
     */
Run Code Online (Sandbox Code Playgroud)

H/T 这家伙 -> https://medium.com/@nebkam/symfony-deprecated-route-and-method-annotations-4d5e1d34556a


Str*_*bek 9

这是我找到的解决方案.这篇文章对我的调整帮了我很多.3没有.3而不是添加config/packages/framework_extra.yaml,我已将该设置添加到我的config.yml.