我已经从 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 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 检查吗?
谢谢...
最佳答案
只需注入(inject) request_stack
而不是 request
并调用 getCurrentRequest() .
关于php - Symfony 2.8 : isScopeActive deprecation after update to 2. 8.0 来自 2.7.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34136957/