0

我正在使用 Form/Type FormBuilder 来设置表单。但是我怎样才能从存储库中获取数据到表单类型中呢?下面的代码不起作用。

Using a Custom Query for the Entities

If you need to specify a custom query to use when fetching the entities (e.g. you only want to return some entities, or need to order them), use the query_builder option. The easiest way to use the option is as follows:


use Doctrine\ORM\EntityRepository;
// ...

$builder->add('users', 'entity', array(
    'class' => 'AcmeHelloBundle:User',
    'query_builder' => function(EntityRepository $er) {
        return $er->createQueryBuilder('u')
            ->orderBy('u.username', 'ASC');
    },
));
4

1 回答 1

0

property您需要使用属性指定将哪个实体字段用作每个选项的标签- http://symfony.com/doc/current/reference/forms/types/entity.html#basic-usage

- 或者 - -

您可以省略property属性并__toString()为您的实体添加魔术方法。这样,您将可以更好地控制将用作选项标签的内容。

于 2013-10-21T15:08:58.623 回答