| Q | A
| --- | ---
| Bug Report? | yes
| Feature Request? | no
| BC Break Report? | no
| RFC? | yes
| Imagine Bundle Version | 2.0.x-dev
I want to use this bundle to resize image temporary prior to tweet it with my controller class.
I'm currently doing this:
$imagineCacheManager = $this->get('liip_imagine.cache.manager');
$resolvedPath = $imagineCacheManager->getBrowserPath($this->getParameter('webcams_directory').'/'.$imagen->getPath(), 'twitter_image');
My filter is setted up like this:
twitter_image:
quality: 75
filters:
relative_resize:
widen: 1024
heighten: 768
The problem is with $imagineCacheManager = $this->get('liip_imagine.cache.manager'); line as it throws this error:
The "liip_imagine.cache.manager" 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.
I think maybe this is a bug with symfony 4 or I've to set that class public somewhere and somehow but I don't know how...
Services in the symfony container are now private by default and that's a good thing ;)
You may want to inject the services into your controller instead of grabbing it dynamically.
Can you show me some code how to inject it?
Sure thing - assuming you're using Symfony 3.x:
For a controller you would do something along the lines of:
# config/services.yaml
services:
app.controller.thumbnail:
class: AppBundle\Controller\ThumnailController
arguments:
- '@liip_imagine.cache.manager'
And the controller:
class ThumbnailController extends Controller {
private $cacheManager;
public function __construct(CacheManager $cacheManager) {
$this->cacheManager = $cacheManager;
}
public function myAction() {
// $this->cacheManager->...
}
}
Depending on whether you're using annotation based routes, or not, you need to add service="app.controller.thumbnail" to your @Route annotation.
Further information:
A friendly advice: I know it's not mission critical for you, but the service container is one of the center pieces of the framework itself. You might want to look into the documentation and then read the container configuration of the FrameworkBundle to get a glimpse on how it all fits together. I'm pretty sure this will greatly extend your skills and your ability to do things with the framework.
Most helpful comment
Sure thing - assuming you're using Symfony 3.x:
For a controller you would do something along the lines of:
And the controller:
Depending on whether you're using annotation based routes, or not, you need to add
service="app.controller.thumbnail"to your@Routeannotation.Further information:
A friendly advice: I know it's not mission critical for you, but the service container is one of the center pieces of the framework itself. You might want to look into the documentation and then read the container configuration of the FrameworkBundle to get a glimpse on how it all fits together. I'm pretty sure this will greatly extend your skills and your ability to do things with the framework.