Symfony 2.8:isScopeActive 从 2.7.7 更新到 2.8.0 后弃用 [英] Symfony 2.8: isScopeActive deprecation after update to 2.8.0 from 2.7.7

查看:35
本文介绍了Symfony 2.8:isScopeActive 从 2.7.7 更新到 2.8.0 后弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从 2.7.7 更新到 symfony 2.8,但我得到了这个弃用:

I've updated to symfony 2.8 from 2.7.7 and i get this deprecation:

Symfony\Component\DependencyInjection\Container::isScopeActive方法自 2.8 版起已弃用,将在 3.0 中移除.

The Symfony\Component\DependencyInjection\Container::isScopeActive method is deprecated since version 2.8 and will be removed in 3.0.

我在树枝扩展类中使用这个调用:

I use this call in a twig extension class:

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
    }

首先我删除了 isScopeActive 检查,但是当我运行 symfony 缓存清除时出现异常:

Firstly i delete the isScopeActive check, but i get an exception when i run the symfony cache clear:

[Symfony\Component\DependencyInjection\Exception\InactiveScopeException]您不能创建非活动范围的服务(请求")(请求").

[Symfony\Component\DependencyInjection\Exception\InactiveScopeException] You cannot create a service ("request") of an inactive scope ("request").

有什么办法可以替代 isScopeActive 检查吗?

Is there any way to replace the isScopeActive check?

谢谢...

推荐答案

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

Simply inject request_stack instead of request and call getCurrentRequest().

这篇关于Symfony 2.8:isScopeActive 从 2.7.7 更新到 2.8.0 后弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆