Symfony 2 passing array in service.xml
arrays, connection, service, symfony, xml
Solution
Еhis example should clarify the principle:
In *.yml
some_id:
class: %some.class%
arguments:
- %some.argument%,
- [tags: [environment: %kernel.environment%, debug:%kernel.debug%]]
In *.xml
<service id="some_id" class="%some.class%">
<argument>%some.argument%</argument>
<argument type="collection">
<argument key="tags" type="collection">
<argument key="environment">%kernel.environment%</argument>
<argument key="debug">%kernel.debug%</argument>
</argument>
</argument>
</service>
Problem
I have services in my services.xml ``` <service id="my.connection" class="Doctrine\Bundle\DoctrineBundle\ConnectionFactory"> </service> <service id="my.main" class="%my.main.class%"> <call method="foo"> <argument type="service" id="tmcyc.connection" /> </call> </service> ``` But got error: Catchable Fatal Error: Argument 1 passed to Doctrine\Bundle\DoctrineBundle\ ConnectionFactory::__construct() must be an array, none given... How can I pass array with argument? For example: ``` <service id="my.connection" class="Doctrine\Bundle\DoctrineBundle\ConnectionFactory"> <argument>[ARRAY]</argument> </service> ``` or maybe I'm doing somthing wrong? Because this code works greate: ``` $connectionFactory = $this->getContainer()->get('doctrine.dbal.connection_factory'); $conn = $this->createConnection($this->conn); $conn->executeQuery('SET NAMES utf8'); ```