简体   繁体   English

在自定义类(Symfony2)中使用参数值

[英]Use paramater value in a custom class (Symfony2)

I have some parameter values in app/config/parameters.yml 我在app / config / parameters.yml中有一些参数值

parameters:
    database_host: 127.0.0.1
    database_port: null
    database_name: database_name
    ...
    igv: 0.18
    isc: 0.18

Now, I want to use the parameters in a Custom class in AppBundle/CustomClass.php. 现在,我想在AppBundle / CustomClass.php中的Custom类中使用参数。 How can I use this parameters? 如何使用此参数? I try $this->container->get('igv') but not works. 我尝试$ this-> container-> get('igv'),但不起作用。

In services.yml: 在services.yml中:

my_app.customclass:
    class:  AppBundle\CustomClass
    arguments: ['%igv%', '%isc%']

Add the arguments to the constructor of AppBundle\\CustomClass. 将参数添加到AppBundle \\ CustomClass的构造函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM