发布于 2014-12-29 08:02:59 | 208 次阅读 | 评论: 1 | 来源: PHPERZ

这里有新鲜出炉的Symfony 中文指南,程序狗速度看过来!

Symfony开源的PHP开发框架

Symfony是一个基于MVC模式的面向对象的PHP5框架。Symfony允许在一个web应用中分离事务控制,服务逻辑和表示层。


本文为大家讲解的是Symfony2 错误:Scope Widening Injection detected解决方法,感兴趣的同学参考下.

错误描述

当servive arguments 为[@request]时候出现这个报错

Uncaught exception 
'Symfony\Component\DependencyInjection\Exception\ScopeWideningInjectionException'
 with message 'Scope Widening Injection detected: The definition 
"user.registration_initilize" references the service "request" which 
belongs to a narrower scope. Generally, it is safer to either move 
"mc_user.registration_initilize" to scope "request" or alternatively 
rely on the provider pattern by injecting the container itself, and 
requesting the service "request" each time it is needed.

解决方法

在symfony2中Service分两种 一个container 一个prototype 。

container是保存一个实例供多次使用

prototype是每次使用都会生成一个新的实例

这两者加入service参数是没问题的

但是 对于request每个子请求(subrequest)都会生成新的实例 跟前面两者又不一样

这里要把[@request] 换成 [@request_stack]

request_stack 即$this->getCurrentRequest()

这时候就在service中能获取当前的请求参数或者session了



最新网友评论  共有(1)条评论 发布评论 返回顶部
nhs 发布于2016-04-30 01:28:12
1W个赞,感谢楼主!
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务