Answer the question
In order to leave comments, you need to log in
Accessing parameters from a Symfony 2 repository
A fairly simple thing - but I just can’t find how to do this :(
Let's say I want to make a method that downloads data via FTP
The method is placed in the repository
The data for accessing FTP is placed in config.yml in "parameters:"
So - as a method from the repository get data from config.yml - this is done easily from the controller, but I don’t want to receive it and pass it to the method every time before calling the method.
Tell me how to do this, thanks in advance)
Answer the question
In order to leave comments, you need to log in
the repository is the repository of the doctrine - the class is the heir to Doctrine \ ORM \ EntityRepository,
I understand you correctly?
it is impossible to get parameters from the repository, the developers did not provide for this possibility.
Because it would be wrong to do so.
Repositories contain methods that store the logic of complex data fetches from the database. They don't need anything else. And if necessary, methods have parameters.
FTP is not a database.
For this, I would recommend that you make a service for these purposes.
And parameters are easily substituted into the service through the constructor or set methods through the DI container.
See how they do it in the mail example in the official documentation .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question