在Symfony2.7中,我可以直接从控制器向表单类型构造函数传递参数来创建表单,但是在Symfony3中,我无法这样做!
$postedBy = $this->getUser()->getFullname();
$form = $this->createForm(new NewsType($postedBy));
在Symfony3之后
$form = $this->createForm(NewsType::class); // no idea how to pass parameter?
更新: 我也想从以下位置访问它:
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
// how to access posted_by_name here which is sent from controller
}
非常感谢任何帮助..