我的下面有一张图片public
folder.
如何在 symfony 4 中获取我的图像目录?
在 symfony 3 中,它的等价物是:
$webPath = $this->get('kernel')->getRootDir() . '/../web/';
这是一个不好的做法注入整个container
,如果您不在控制器中,则仅用于访问参数。只需自动接线ParameterBagInterface
像这样,
protected $parameterBag;
public function __construct(ParameterBagInterface $parameterBag)
{
$this->parameterBag = $parameterBag;
}
然后像这样访问你的参数(在本例中是项目目录),
$this->parameterBag->get('kernel.project_dir');
希望有人会觉得这有帮助。
Cheers.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)