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
我已经从 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.
我在 twig 扩展中使用这个调用 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 缓存时我得到一个异常:
[Symfony\Component\DependencyInjection\Exception\InactiveScopeException]
You cannot create a service ("request") of an inactive scope
("request").
有什么方法可以替代 isScopeActive 检查吗?
谢谢...
只需注入 request_stack
而不是 request
并调用 getCurrentRequest().
我已经从 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.
我在 twig 扩展中使用这个调用 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 缓存时我得到一个异常:
[Symfony\Component\DependencyInjection\Exception\InactiveScopeException] You cannot create a service ("request") of an inactive scope ("request").
有什么方法可以替代 isScopeActive 检查吗?
谢谢...
只需注入 request_stack
而不是 request
并调用 getCurrentRequest().