Reu*_*ven 12
假设你创建了一个FormType类.您不知道如何在此对象中传递容器.
现在创建从FormType扩展的自己的类型,并通过构造函数传递容器
class MyType extends FormType
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
}
Run Code Online (Sandbox Code Playgroud)
在config.yml中,定义新类型
mytype:
class: ...\MyType
arguments: ["@service_container"]
tags:
- { name: form.type }
Run Code Online (Sandbox Code Playgroud)
现在,在所有控制器中使用MyType而不是FormType
| 归档时间: |
|
| 查看次数: |
4487 次 |
| 最近记录: |