symfony配置
1、获取配置的一些变量
在HttpFoundation/Kernel.php 文件里面有函数 getKernelParameters ()可以获取一些配置变量的数组。有需要可以从那里获取。
2、配置service参数
parameters:
cellcom.file.config:
upload_path: /mnt/upload/
首先service.yml 的参数栏配置参数,接下来是service调用该参数
cellcom.file:
class: Cellcom\Service\Content\FileService
arguments: [%cellcom.file.config%]
说明:class即指明service地址,arguments里面即是传入该参数,此时参数类型是数组。
接下来在Fileservice里面就可以调用该参数了
public function __construct($upload_path)
{
$this->upload_path = $upload_path['upload_path'];
}
3、service调用其它service
可以直接在service.yml里面把container注入到要调用的service
arguments: [@container]
这样就可以通过$this->container->get()方法调用其它服务。