我正在使用 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');
},
));