Let say you created a FormType
class. You don't know how to pass the container in this object.
Create now your own type extended from FormType and pass the container through the constructor
class MyType extends FormType
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
}
In your config.yml, define your new type
mytype:
class: ...MyType
arguments: ["@service_container"]
tags:
- { name: form.type }
Now, use MyType instead of FormType in all your controllers
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…