How do i refer to a data file in the services.yml, which is located in the same or any bundle?
Im shipping a csv-file which i would like to inject as argument.
It works when i use the direct path:
mybundle.data.csv: %kernel.root_dir%/../vendor/mybundle/my-bundle/mybundle/MyBundle/Resources/data/data.csv
This is pretty verbose and unflexible and thus i am looking for a resolver like:
data.csv: "@MyBundle/Resources/data/data.csv"
But this is not working:
… has a dependency on a non-existent service
“mybundle/resources/data/data.csv”.
any ideas?
First of all: in the YAML service and parameter definitions @ also refers to another service. That is why your code does not work.
Basically you have two possibilities. The first and simple one is to use a relative path in your bundles
services.ymland append it in your CSV class.For example:
In the class you want to read the CSV file:
The other possibility is to make the filename of the CSV file configurable via
config.yml(see this article in the Symfony2 cookbook) and insert a special placeholder in the config value that you replace in yourAcmeDemoBundleExtensionclass:Your
config.ymlwould look like: