2012-12-10 4 views
6

ORMPHP/Symfony2のフォームチェックボックスフィールド

My\SampleBundle\Entity\Subject: 
    type: entity 
    id: 
     id: 
      type: integer 
      generator: { strategy: AUTO } 
    fields: 

     // ... 

     motion: 
      type: smallint 
      unsigned: true 

タイプ

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    // ... 

    $builder->add('motion', 'checkbox', array(
     'required' => false 
    )); 

    // ... 
} 

エラー

期待型の引数 "ブール"、 "整数" は、与えられた


チェックボックスをオンまたはオフにしたいと考えています。 値は0と1で分配されます。
値パラメータを指定しても無駄でした。

$builder->add('motion', 'checkbox', array(
    'value'  => 1, 
    'required' => false 
)); 

どうすればよいですか?

答えて

10

ORMマッピング定義では、smallintの代わりにmotionをブール値として定義する必要があります。そして、FYIでは、SymfonyはTINYINTをbooleanと整数型の他の整数SQL型として解釈します。

My\SampleBundle\Entity\Subject: 
    type: entity 
    id: 
     id: 
      type: integer 
      generator: { strategy: AUTO } 
    fields: 

     // ... 

     motion: 
      type: boolean 
+1

ありがとうございます。あなたは確かに私のために簡単にものを作った。 –

関連する問題