我想了解symfony中的服务
我想尝试创建我的服务
在我的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']
参数作为参数传递给您的服务构造函数:
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)
| 归档时间: |
|
| 查看次数: |
65 次 |
| 最近记录: |