2 개의 결합 된 개체에서 양식을 만들 수 있습니까?Symfony2 + Doctrine2/2 개의 결합 된 개체에서 양식 만들기
나는 하나의 관계에 합쳐진 두 개의 개체 property
& propertylanguage
을 가지고 있습니다. (하나의 속성은 많은 언어를 가질 수 있습니다)
언어는 title
및 description
개의 열을 가지고 있습니다. 하나의 속성은 영어, 프랑스어, 독일어 제목을 가질 수 있습니다.
나는 그 중에서 하나의 양식을 만들려고 노력하고 있습니다. 아래를 참조하십시오.
컨트롤러 : addProperty.php
class AddPropertyController extends Controller
{
// ....
public function indexAction(Request $request)
{
$property = new property;
$language = new propertyLanguage;
$property ->addpropertylanguage($language);
$form = $this->createForm(new propertyType($this->getDoctrine()),$property);
// .....
}
양식 유형 : propertType.php
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('title', 'text');
// other ->add() below.
}
그것은 다음과 같은 오류 반환 : 물론
Neither property "title" nor method "getTitle()" nor method "isTitle()" exists in class "\defaultBundle\Entity\property"
이를 적절한 속성에 제목이 있지만 속성 언어에 하나가 있습니다. 시도해도 : -> add ('title', 'entity', array ('class'=> defaultBundle : propertylanguage)); 작동하지 않습니다.
도와 주셔서 감사합니다.
최고,
피에르.
안녕하세요. 시간과 도움을 많이 주셔서 감사합니다. 실제로 엔터티 개체에서 양식을 작성하려면 작동하지 않는다고 생각하기 때문에 queryBuilder를 사용하지 않는 것이 좋습니다. 인스턴스에서 $ form = $ this-> createForm (새 속성 유형 ($ this-> getDoctrine()), $ property); 나는 모범 사례를 보이는 서사드 대답을하러 갈 것이다. 시간을 내 주셔서 다시 한 번 감사합니다. – 123pierre
안녕하세요, 저는 한 번 프로젝트를 위해 한 번 사용해 보았지만 작동하지만 Cerad 솔루션도 확실히 작동합니다! 해피 코딩;) – SebScoFr