여러 개의 etape를 추가 할 수있는 양식을 만들고 싶습니다. 나는이 같은 형태를 만듭니다Symfony 2 양식, 필드 컬렉션이 표시되지 않습니다.
// FORM
namespace RBO\TryBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use RBO\TryBundle\Entity\Try;
class TryType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('etapes', 'collection', array(
'type' => new EtapeType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'label' => 'Etapes'
));
}
public function getName()
{
return 'try';
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'RBO\TryBundle\Entity\Try',
'csrf_protection' => true,
'csrf_field_name' => '_token',
// a unique key to help generate the secret token
'intention' => 'try_item',
);
}
}
// EtapeType
<?php
namespace RBO\TryBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use RBO\TryBundle\Entity\Etape;
class EtapeType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name', 'text');
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'RBO\TryBundle\Entity\Etape',
);
}
public function getName()
{
return 'etape';
}
}
나뭇 가지 템플릿는 // 표시
{{ form_row(form.etapes) }}
실체가 올바른지 시험해보십시오. ArrayCollection 인 etape (생성자에서 정의 됨)
이 코드는 레이블을 기대하지 않습니다. 내가 뭐 놓친 거 없니?
미리 난 항상 임베디드 형태를 렌더링하는 form_widget을 사용했다
실제로 텍스트 필드 이름이나 etapes는 표시되지 않습니다. 난 그냥 레이블이 있고 다른 건 없어요! 내가 추가하고 제거 버튼을 다루는 자바 스크립트 함수를 추가 할 필요가 있지만 그 후에 할 것입니다 읽었습니다! – user979276