Symfony-services.yml这个文件是干啥的

先来看一个简单的services.yml

// src/Nlc/InformationBundle/Resources/config/services.yml
services:
   nlc_information:
       class: Nlc\InformationBundle\Service\ZcService
       arguments: ["初始化参数1", "初始化参数2"]

如果你在控制器中任意一个方法里打印 $this->container->getServiceIds() 会发现 nlc_information 就在里面,

也就是说nlc_information是一个service的ID是唯一标识符

class: 后面跟的就是这个service

arguments: 后面跟的是实例化这个类的时需要给的到的参数 fcuntion _construct(参数1,参数2)

============

查看已经注册的service的方法是在命令行 (symfony3.1)

php bin/console debug:container 

查看指定service的信息为

php bin/console debug:container zc_service
E:\wwwroot\Symfony2\symfony-demo>php bin/console debug:container zc_service

Information for Service "zc_service"
====================================

 ------------------ --------------------
  Option             Value
 ------------------ --------------------
  Service ID         zc_service
  Class              AppBundle\Utils\Zc
  Tags               -
  Public             yes
  Synthetic          no
  Lazy               no
  Shared             yes
  Abstract           no
  Autowired          no
  Autowiring Types   -
 ------------------ --------------------

具体的Option有以上这么多,我也没有全整明白

只要是注册到container里的service可以通过 $this->get('zc_service')  获得这个service的实例

 

posted on 2016-07-20 13:52  Zack86  阅读(567)  评论(0编辑  收藏  举报

导航