【发布时间】:2019-02-24 16:48:07
【问题描述】:
我已经安装了 Liip 包,我需要的类在我的容器中很明显可用,因为这是我的 debug:container 命令的结果:
$ bin/console debug:container
liip_imagine.service.filter Liip\ImagineBundle\Service\FilterService
只是为了告诉你它在那里,这是我的文件夹结构的图片:
这是我在控制器中用来访问它的代码:
public function saveProfileEditAction(Request $request)
{
$user = $this->getUser();
$imagine = $this
->container
->get('liip_imagine.service.filter');
这是我得到的错误:
The "liip_imagine.service.filter" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
我想我需要知道如何公开?
这是我的 yaml 文件的样子:
liip_imagine :
# configure resolvers
resolvers :
# setup the default resolver
default :
# use the default web path
web_path : ~
# your filter sets are defined here
filter_sets :
# use the default cache configuration
cache : ~
# the name of the "filter set"
my_thumb :
# adjust the image quality to 75%
quality : 75
# list of transformations to apply (the "filters")
filters :
# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail : { size : [120, 90], mode : outbound }
thumb_square : { size : [300, 300], mode : outbound }
thumb_rectangle_md : { size : [670, 400], mode : outbound }
thumb_hd : { size : [1920, 1080], mode : outbound }
# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [124, 94], position : center, color : '#000000' }
【问题讨论】:
-
您的 IDE 似乎无法识别类的命名空间。我说的是红色字母和黄色突出显示。确保您已运行 composer install 并且您已正确设置自动加载文件。
-
该服务很可能不是公开的,因此无法从容器中检索。这是默认行为,以阻止人们过度使用 ContainerAware,因为它被认为是一种不好的做法。您可以通过将服务名称添加到
debug:container或使用debug:autowiring来检查(我认为)。