[英]Symfony inject parameter in repository
I need inject parameter in repository, I try add calls to service repo but my call function not call when I call some function from my repo 我需要在存储库中注入参数,我尝试添加对服务存储库的调用,但是当我从存储库中调用某个函数时,我的调用函数未调用
app.repository.file:
class: "%app.repository.file.class%"
factory_service: doctrine.orm.default_entity_manager
factory_method: getRepository
arguments:
- "%app.entity.file.class%"
calls:
- [setParam,['%md5_suffix%']]
setParam not call setParam不调用
private $param;
public function setParam($param)
{
$this->param = $param;
}
param have null
参数为
null
and I try use JMSDiExtraBundle 我尝试使用JMSDiExtraBundle
/**
* @DI\InjectParams({
* "param" = @DI\Inject("%md5_suffix%"),
* })
*/
public function setParam($param)
{
$this->param = $param;
}
but have in property %md5_suffix%
like string, not property from parameters.yml
:) 但是具有
%md5_suffix%
属性,例如字符串,而不是parameters.yml
属性:)
how to inject parameter from parameters yml in repo ? 如何从回购中的参数yml注入参数?
Factory_service is deprecated in 2.8. 2.8中不建议使用Factory_service。 Instead, try using something like:
相反,请尝试使用类似以下内容的方法:
app.repository.file:
class: Doctrine\ORM\EntityRepository
factory: ['@doctrine.orm.entity_manager', getRepository]
arguments:
- "%app.entity.file.class%"
calls:
- [setParam,['%md5_suffix%']]
I create another service 我创建另一个服务
economy.param_helper:
class: "%economy.param_helper.class%"
arguments:
- "%md5_suffix%"
and inject this service in repo like this 并像这样在回购中注入这项服务
/**
* @var ParamHelper
*/
private $param;
/**
* @DI\InjectParams({
* "param" = @DI\Inject("economy.param_helper"),
* })
*/
public function setParam(ParamHelper $param)
{
$this->param = $param;
}
and call $md5Suffix = $this->param->getMd5Suffix();
并调用
$md5Suffix = $this->param->getMd5Suffix();
But I'am not sure this is right way 但是我不确定这是正确的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.