How to pass arguments to a service's __construct() method when autowiring it to a controller? #57448
Unanswered
VitaliyMarkelov
asked this question in
Q&A
Replies: 1 comment
-
Hey, please have a look at the documentation. You can either use the service definition and pass it in the yaml/xml/php |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Say I have a service
and a controller:
and these work perfectly OK. In my case I would like to pass init parameters to my service, so I changed constructor:
and get error. How can I pass an argument to MyService constructor? May be this just a wrong (non-symfonysh) approach and/or bad coding habit, then I would love to get an advice on a good approach. If there a doc that discusses this it would be just wonderful. I have watched and rewatched SymfonyCasts Creating Your Own Service from Cosmic Coding with Symfony 7 to no avail ).
Beta Was this translation helpful? Give feedback.
All reactions