【问题标题】:How to create entity formtype from a non related entity (Symfony2)?如何从非相关实体(Symfony2)创建实体表单类型?
【发布时间】:2014-01-07 14:35:36
【问题描述】:

例如,如果您有以下实体和关系:

PurchasedService * ---> 1 个服务 * ---> 1 个 ServiceCategory

如何创建一个 formType,列出 PurchasedServiceType 中 ServiceCategory 中的所有条目?

作为:

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

导致错误:

既不是属性“servicecategory”也不是其中一种方法 “getServicecategory()”、“isServicecategory()”、“hasServicecategory()”、 “__get()” 存在并在...中具有公共访问权限

我希望直接调用实体 ServiceCategory?

【问题讨论】:

    标签: symfony doctrine getter-setter many-to-one


    【解决方案1】:

    它应该。但我觉得你错过了命名空间。在您的情况下,您有:

    'class' => 'InvoicingBundle:ServiceCategory',
    

    总是 InvoicingBundle 本地化在某个目录中 - 你应该有 src/{theMissingDirectory}/InvoicingBundle/Entity/ServiceCategory ,所以模式是:

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

    例如:

    'class' => 'AcmeInvoicingBundle:ServiceCategory',
    

    请以这种方式尝试,它应该可以工作。

    问候,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多