Symfony 2在service.xml中传递数组
发布时间:2020-12-16 23:26:01 所属栏目:百科 来源:网络整理
导读:我在services.xml中有服务 service id="my.connection" class="DoctrineBundleDoctrineBundleConnectionFactory"/serviceservice id="my.main" class="%my.main.class%" call method="foo" argument type="service" id="tmcyc.connection" / /call/servic
我在services.xml中有服务
<service id="my.connection" class="DoctrineBundleDoctrineBundleConnectionFactory"> </service> <service id="my.main" class="%my.main.class%"> <call method="foo"> <argument type="service" id="tmcyc.connection" /> </call> </service> 但得到错误:
如何通过参数传递数组? <service id="my.connection" class="DoctrineBundleDoctrineBundleConnectionFactory"> <argument>[ARRAY]</argument> </service> 或者我做错了什么?因为这段代码很有用: $connectionFactory = $this->getContainer()->get('doctrine.dbal.connection_factory'); $conn = $this->createConnection($this->conn); $conn->executeQuery('SET NAMES utf8'); 解决方法
这个例子应该澄清原则:
在* .yml some_id: class: %some.class% arguments: - %some.argument%,- [tags: [environment: %kernel.environment%,debug:%kernel.debug%]] 在* .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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |