2014-07-11 8 views
0

저는 양식 상속을 사용하고 있습니다. 내 '제목'(이미 내 BookType에 있음)에 클래스를 추가하거나 대체하려고합니다. 제발 어떻게 할 수 있니?Symfony - 양식 상속 - 새 속성을 무시하거나 추가하는 방법은 무엇입니까?

class ValidationBookType extends BookType { 

    public function buildForm(FormBuilderInterface $builder, array $options) { 
     parent::buildForm($builder, $options); 
     $builder 

       ???????????????????????????????????????? 
       ->add('title', 'text', array(
        'attr' => array(
         'class' => 'newclass' 
        ) 
       )) 
       ???????????????????????????????????????? 
     ; 
    } 

    /** 
    * @param OptionsResolverInterface $resolver 
    */ 
    public function setDefaultOptions(OptionsResolverInterface $resolver) { 
     $resolver->setDefaults(array(
      'data_class' => 'Video2Learn\BddBundle\Entity\Book', 
      'cascade_validation' => true, 
     )); 
     $resolver->setRequired(array(
      'step', 
     )); 
    } 

    public function getName() { 
     return 'Book'; 
    } 

} 

->setAttribute(?

감사합니다.

편집해결책

내가 해결책을 찾았지만 더 나은 방법이 ...이있을 수 있습니다 발견?

class ValidationBookType extends BookType { 

    public function buildForm(FormBuilderInterface $builder, array $options) { 
     $parent = parent::buildForm($builder, $options); 
     $array = $parent->get('title')->getOptions(); 
     $array['read_only'] = true; 

     $builder 
       ->remove('title') 
       ->add('title', 'text', $array) 


     ; 
    } 

가 어떻게 그것을 향상시킬 수

내가 그랬어? 더 일반적인 방법이 있습니까? > ('제목을'추가 ... 등 -

class ValidationBookType extends BookType { 

    public function buildForm(FormBuilderInterface $builder, array $options) { 
     $parent = parent::buildForm($builder, $options); 
     $array = $parent->get('title')->getOptions(); 
     $array['read_only'] = true; 

     $builder 
       ->remove('title') 
       ->add('title', 'text', $array) 


     ; 
    } 
+0

가장 좋은 방법이 될 수 있지만, 당신이 할 수있는'$ 형상 -> 제거 ('제목') : – qooplmao

+0

나는 내 게시물을 편집합니다 :) – Zagloo

답변

0

나는이의 문제를 해결)`.
관련 문제