I'm using sonata admin and mediabundle in symfony 3.2 application.
composer.json
"sonata-project/admin-bundle": "3.x-dev",
"sonata-project/doctrine-orm-admin-bundle": "4.x-dev",
"sonata-project/media-bundle": "4.x-dev",
"sonata-project/intl-bundle": "2.x-dev"
I generate mediabundle as said in doc
sf3 sonata:easy-extends:generate --dest=src SonataMediaBundle
Then in my entity I add a relation with media entity:
/**
* @ORM\OneToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"})
* @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $image;
I configure sonata media as said in doc:
sonata_media:
db_driver: doctrine_orm
default_context: default
contexts:
default:
providers:
- sonata.media.provider.image
- sonata.media.provider.file
formats:
small: { width: 100 , quality: 70}
big: { width: 500 , quality: 70}
filesystem:
local:
directory: "%kernel.root_dir%/../web/uploads/media"
cdn:
server:
path: /uploads/media # http://media.sonata-project.org/
and then added it to my admin
->add('logo', 'sonata_type_model_list', array('required' => false), array(
'link_parameters' => ['provider'=>'sonata.media.provider.image'],
'label' => 'Logo',
'context' => 'default',
'required' => false,
))
When i try to add an image i get this error:
You have requested a non-existent service "request". Did you mean one of these: "data_collector.request", "monolog.logger.request", "request_stack", "router.request_context", "sonata.intl.locale_detector.request_stack", "validate_request_listener"?
So i try to understand where it use $this->container->get('request') but i find out that in sonata code it use something like:
if ($this->container->has('request_stack')) {
return $this->container->get('request_stack')->getCurrentRequest();
}
return $this->container->get('request');
That seems to be right. So why i get this error?