Php 从EntityType查询数据
我正在使用Form/Type FormBuilder设置表单。但是,如何将数据从存储库中获取到表单类型中呢?下面的代码不起作用Php 从EntityType查询数据,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我正在使用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 th
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');
},
));
您需要使用
property
attribute-
--或---
您可以省略
属性
属性,并将\uuuu toString()
魔术方法添加到实体中。这样,您就可以更好地控制将用作选项标签的内容。这对您有帮助吗?