New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symfony 4 - Service "jms_serializer" not found #713
Comments
With symfony 4, you should inject the serializer service into your controller somehow. see https://symfony.com/doc/current/service_container/injection_types.html#constructor-injection One way is to declare it in the constructor. |
Okay I think I understand but how do I call jms_serializer? like this: EDIT: I found. We must do SerializerInterface $serializer. |
@goetas, even though there is no issue with the code, there is one with the documentation. |
@nreynis thanks for pointing out this. |
one the ways is to use
after it will be available in the container with the following name that are you define it the information about that you can find here https://symfony.com/doc/current/service_container/service_subscribers_locators.html |
gives me "Call to a member function get() on null" :( |
You must set container content before calling get(). Pass the ContainerInterface to $this->setContainer() in AbstractController. |
Thank you. I got the container now, but I always get the message that the service "jms_interface" or "JMS\Serializer\SerializerInterface" (through dependency injection) is not running. So I think I am missing something. How can I make sure this service is started/running? I'm new at Symfony. Edit: |
Hello,
I discovered Symfony 4 and I wanted to use the jms_serializer service. So I used the following command:
php composer require jms / serializer-bundle
And in my code I use:
$ this-> get ('jms_serializer') -> serialize ($ object, 'json');
But I have the following error:
Service "jms_serializer" not found: even though it exists in the app's container, the container inside "App\Controller\ArticleController" is a smaller service locator that only knows about the "doctrine", "http_kernel", "parameter_bag", "request_stack", "router" and "session" services.Try using dependency injection instead.
Yet they do not say in the documentation that I have to use addiction injection.
What do I have to do?
If I have to use dependency injection can you give me a code example that I understand how to use it?
A big thank you in advance.
The text was updated successfully, but these errors were encountered: