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');
},
));