2014-01-07 44 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,