2014-01-07 68 views
0

如果你有例如下面的實體和關係:如何從非關聯實體(Symfony2)創建實體表單類型?

PurchasedService * ---> 1個服務* ---> 1 ServiceCategory

你怎麼可以創建一個formType列出所有條目從ServiceCategory PurchasedServiceType內?

由於:

$builder 
     ->add('servicecategory', 'entity', array(
      'class' => 'InvoicingBundle:ServiceCategory', 
      'query_builder' => function(EntityRepository $er) { 
       return $er->createQueryBuilder('sc') 
        ->orderBy('sc.serviceCategoryName', 'ASC'); 
      }, 
     )) 

結果錯誤:

Neither the property "servicecategory" nor one of the methods "getServicecategory()", "isServicecategory()", "hasServicecategory()", "__get()" exist and have public access in...

我希望直接調用實體ServiceCategory?

回答

0

它應該。但我覺得你錯過了命名空間。在你的情況有:

'class' => 'InvoicingBundle:ServiceCategory', 

始終將InvoicingBundle在某些目錄本地化 - 你應該有SRC/{theMissingDirectory}/InvoicingBundle /實體/ ServiceCategory,這樣的格局是:

'class' => '{theMissingDirectory}InvoicingBundle:ServiceCategory', 

在例如:

'class' => 'AcmeInvoicingBundle:ServiceCategory', 

請試試這樣,它應該工作。

Regards,