フラットな php プロジェクトを Symfony2 に移行しようとしていますが、非常に難しくなっています。たとえば、いくつかの仕様を持ち、その Extraspecs DB テーブルの「cat」属性によって区別できる製品仕様のテーブルがあります。したがって、そのテーブルのエンティティを作成し、「cat」= 0 の仕様だけの配列を作成したいと考えています...
コードはこれだと思います..そうですか?
$typeavailable = $this->getDoctrine()
->getRepository('LabsCatalogBundle:ProductExtraspecsSpecs')
->findBy(array('cat' => '0'));
これを配列に入れて、このようなフォームで動作させるにはどうすればよいですか?:
form = $this ->createFormBuilder($product)
->add('specs', 'choice', array('choices' => $typeavailableArray), 'multiple' => true)
前もって感謝します :)
#皆さん、ありがとうございました..
しかし今、私は別の問題に遭遇しました..実際、私は既存のオブジェクトからフォームを構築しています:
$form = $this ->createFormBuilder($product)
->add('name', 'text')
->add('genspec', 'choice', array('choices' => array('0' => 'None', '1' => 'General', '2' => 'Specific')))
->add('isReg', 'choice', array('choices' => array('0' => 'Material', '1' => 'Reagent', '2' => 'Antibody', '3' => 'Growth Factors', '4' => 'Rodents', '5' => 'Lagomorphs')))
その場合、私の現在の値は「extraspecs」という名前なので、次のように追加しました。
->add('extraspecs', 'entity', array(
'label' => 'desc',
'empty_value' => ' --- ',
'class' => 'LabsCatalogBundle:ProductExtraspecsSpecs',
'property' => 'specsid',
'query_builder' => function(EntityRepository $er) {
return $er ->createQueryBuilder('e');
しかし、「エクストラスペック」は、すべての製品がいくつかのエクストラスペックを持つ oneToMany の関係から来ています...
ORM は次のとおりです。
Labs\CatalogBundle\Entity\Product:
type: entity
table: orders__regmat
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 100
catnumber:
type: string
scale: 100
brand:
type: integer
scale: 10
company:
type: integer
scale: 10
size:
type: decimal
scale: 10
units:
type: integer
scale: 10
price:
type: decimal
scale: 10
reqcert:
type: integer
scale: 1
isReg:
type: integer
scale: 1
genspec:
type: integer
scale: 1
oneToMany:
extraspecs:
targetEntity: ProductExtraspecs
mappedBy: product
Labs\CatalogBundle\Entity\ProductExtraspecs:
type: entity
table: orders__regmat__extraspecs
fields:
extraspecid:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
regmatid:
type: integer
scale: 11
spec:
type: integer
scale: 11
attrib:
type: string
length: 20
value:
type: string
length: 200
lifecycleCallbacks: { }
manyToOne:
product:
targetEntity: Product
inversedBy: extraspecs
joinColumn:
name: regmatid
referencedColumnName: id
どうすればいいですか?
ありがとうございました!!!