5

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');

3 Answers 3

17

Е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>
Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer, widely more demonstrative.
1

Ok, found the answer

<service id="my.connection" class="Doctrine\Bundle\DoctrineBundle\ConnectionFactory">
    <argument>%doctrine.dbal.connection_factory.types%</argument>
</service>

Comments

0

same with the parameters

In *.xml

    <parameter key="some.key" type="collection">
        <parameter>parameter 1</parameter>
        <parameter>parameter 2</parameter>
    </parameter>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.