내 양식 PRE_SET_DATA
이벤트 리스너로 서비스를 사용하고 싶습니다. 이제이 양식은 다른 양식 유형 CollectionType
으로 삽입됩니다.Symfony2 - 서비스로 컬렉션 유형 양식을 정의하십시오.
services:
form_type_child:
class: IndexBundle\Form\Type\ChildType
arguments:
- @doctrine.orm.entity_manager
그리고 지금은 CollectionType
으로이 양식을 사용해야합니다 : : 지금이 얻을
class ParentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('child', CollectionType::class, array(
'type' => ChildType::class,
'by_reference' => false,
'required' => false
))
->add('submit', SubmitType::class);
}
}
class ChildType extends AbstractType
{
private $entitymanager;
public function __construct(EntityManager $entitymanager)
{
$this->entityManager = $entitymanager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
...
// Add listeners
$builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
}
public function onPreSetData(FormEvent $event)
{
$form = $event->getForm();
...
$this->entityManager->flush();
}
...
}
내가 서비스로 양식 유형을 정의 엔티티 관리자 서비스를 주입하려면 오류 :
Catchable Fatal Error: Argument 1 passed to IndexBundle\Form\Type\ChildType::__construct() must be an instance of Doctrine\ORM\EntityManager, none given, called in C:\xampp\htdocs\trainingexperience_symfony\vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php on line 90 and defined
내가 어떻게 CollectionType
임베디드 양식의 엔티티 관리자를 통과 할 수 있습니까?
와우 그거야이 도움을. 그것은 효과가 있었다. 감사합니다! –
안녕하세요 @IgnasDamunskis 당신을 환영합니다! – Matteo