我已经从 2.7.7 更新到 symfony 2.8,并且我得到了这个弃用:
Symfony\Component\DependencyInjection\Container::isScopeActive
方法自 2.8 版本起已弃用,并将在 3.0 中删除。
我在树枝扩展类中使用此调用:
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]
您无法创建非活动范围的服务(“请求”)
(“要求”)。
有什么方法可以替代 isScopeActive 检查吗?
谢谢...
只需注入request_stack
代替request
并打电话获取当前请求() http://api.symfony.com/master/Symfony/Component/HttpFoundation/RequestStack.html#method_getCurrentRequest.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)