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 に答える