在Service - Symfony中检索参数

mon*_*ser 2 symfony

我想了解symfony中的服务

我已阅读http://symfony.com/doc/2.3/book/service_container.html#creating-configuring-services-in-the-container

我想尝试创建我的服务

在我的config.yml中

services:
    my_service:
        class:        Acme\FooBundle\myService
        arguments:    ['my_param']
Run Code Online (Sandbox Code Playgroud)

在我的控制器中

public function serviceAction(){
        $Myservice = $this->get('my_service');
        return array();
    }
Run Code Online (Sandbox Code Playgroud)

在我的课程/服务

class myService{

    public function __construct() {
        echo "In BaseClass constructor\n";
    }

} 
Run Code Online (Sandbox Code Playgroud)

问题是:如何在班级服务中回复my_param?我想要检索arguments: ['my_param']

dmn*_*ptr 5

参数作为参数传递给您的服务构造函数:

class myService{

    private $my_param;

    public function __construct($param) {
        $this->my_param = $param;
        echo $this->my_param;
        echo "In BaseClass constructor\n";
    }

}
Run Code Online (Sandbox Code Playgroud)