2017-12-17 26 views
0

개인용 응용 프로그램을 개선하려고하지만 embed 양식에 문제가 있습니다. 사실, 나는 광고문에 첨부 된 스킬과 레벨을 선택하기 위해 필드를 추가하려는 advertType 양식을 가지고 있습니다.Symfony embed form ManyToOne 관계

그런 식으로 광고 엔티티, 기술 엔티티, OneToMany 관계 덕분에 보급 및 기술 엔티티를 참조하는 advertSkill 엔티티가 있습니다. level 속성은 advertSkill 엔티티에서 가져온 것입니다.

광 고찰 양식에 기술 필드를 추가하는 방법을 알지 못해 광 고라는 해당 기술과 레벨로 올바르게 저장됩니다.

스킬을 참조하는 광고 엔티티에는 속성이 없습니다. 다음은

, 내 advertType 클래스의 샘플 : 도움을

$builder 
     ->add('date',  DateTimeType::class, array(
      'view_timezone' => 'Europe/Paris', 
      'with_seconds' => true    
     )) 
     ->add('title',  TextType::class) 
     ->add('content', TextareaType::class) 
     ->add('author',  TextType::class) 
     ->add('email',  TextType::class) 
     ->add('image',  ImageType::class) 
     ->add('categories', EntityType::class, array(
      'class'    => 'OCPlatformBundle:Category', 
      'choice_label'  => 'name', 
      'multiple'   => true 
     )) 
     ->add('save',  SubmitType::class); 

덕분에, 나는 내 코드에 대한 자세한 내용을 제공 할 수 있지만, 나는 몇 가지 코드를 삽입 할 때 그것은 단지 추한.

+0

왜 advertSkill 엔티티인가요? 어떤 속성을 가지고 있습니까? 모든 관계 사이에 어떤 관계가 정확히 있습니까? , ID, 날짜, 제목 : 아이디, 레벨, 고라 (고라 엔티티에 ManyToOne), 기술 (ManyToOne 스킬 엔티티) 스킬 엔티티가 포함되어 있습니다 : 고라 엔티티가 포함 ID, 이름 –

+0

AdvertSkill 엔티티는 다음과 같은 속성을 포함 저자, 내용, 게시, 이미지, 카테고리, 응용 프로그램, updatedAt, nb 응용 프로그램, 전자 메일, 슬러그, ip, 사용자 –

답변

0

나는 프랑스 포럼에서 나와 같은 문제에 대한 조언을 읽으려고했으나 스킬 이름과 레벨 이름을 표시하지 않아서 실수를 범했습니다.

내 AdvertType 양식 클래스 :

enter code here  public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
     ->add('advertSkill', EntityType::class, array(
      'class'     => 'OCPlatformBundle:Skill', 
      'choice_label'   => 'name' 
     )) 
     ->add('level', EntityType::class, array(
      'class'    => 'OCPlatformBundle:AdvertSkill', 
      'choices'   => array('Débutant', 'Intermédiaire', 'Expert') 
     )); 
} 

또한, 나는 advertSkill 클래스가 참조하는 두 개의 클래스에 OneToMany 속성 "advertSkill"를 추가 : 내 새로운 AdvertType 양식 클래스는

enter code here   $builder 
     ->add('date',  DateTimeType::class, array(
      'view_timezone' => 'Europe/Paris', // On affiche l'horaire avec le fuseau horaire de Paris 
      'with_seconds' => true    // On ajoute les secondes àl'affichage de l'horaire 
     )) 
     ->add('title',  TextType::class) 
     ->add('content', TextareaType::class) 
     ->add('author',  TextType::class) 
     ->add('email',  TextType::class) 
     ->add('image',  ImageType::class) 
     ->add('categories', EntityType::class, array(
      'class'    => 'OCPlatformBundle:Category', 
      'choice_label'  => 'name', 
      'multiple'   => true 
     )) 
     ->add('advertSkill', CollectionType::class, array(
      'entry_type'  => AdvertSkillType::class 
     )) 
     ->add('save',  SubmitType::class); 

.

나는 그것이 작동하게하는 방법을 모르겠다!