简体   繁体   English

Symfony 2.8:从2.7.7更新到2.8.0后isScopeActive弃用

[英]Symfony 2.8: isScopeActive deprecation after update to 2.8.0 from 2.7.7

I've updated to symfony 2.8 from 2.7.7 and i get this deprecation: 我从2.7.7更新到symfony 2.8,我得到了这个弃用:

The Symfony\\Component\\DependencyInjection\\Container::isScopeActive method is deprecated since version 2.8 and will be removed in 3.0. 从版本2.8开始,不推荐使用Symfony \\ Component \\ DependencyInjection \\ Container :: isScopeActive方法,并且将在3.0中删除它。

I use this call in a twig extension class: 我在twig扩展类中使用此调用:

class TemplateHelper extends \Twig_Extension {

    private $request;

    private $container;


    /**
     * constructor
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container){
        $this->container = $container;

        if( $this->container->isScopeActive('request') ){
            $this->request = $this->container->get('request');
        }
    }
    //...functions
    }

Firstly i delete the isScopeActive check, but i get an exception when i run the symfony cache clear: 首先我删除了isScopeActive检查,但是当我运行symfony cache clear时出现异常:

[Symfony\\Component\\DependencyInjection\\Exception\\InactiveScopeException] You cannot create a service ("request") of an inactive scope ("request"). [Symfony \\ Component \\ DependencyInjection \\ Exception \\ InactiveScopeException]您无法创建非活动范围(“请求”)的服务(“请求”)。

Is there any way to replace the isScopeActive check? 有没有办法替换isScopeActive检查?

Thanks... 谢谢...

只需注入request_stack而不是request并调用getCurrentRequest()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM