I have the following code which displays all the available main pages that can be used when adding sub pages in my project:
$builder->add('subtocontentid',
'entity',
array(
'class'=>'Shout\AdminBundle\Entity\Content',
'property'=>'title',
'query_builder' => function (EntityRepository $repository)
{
return $repository->createQueryBuilder('s')
->where('s.mainpage = ?1')
->setParameter(1, '1')
->add('o开发者_如何学运维rderBy', 's.created ASC');
}
));
In the form, it works alright. It displays the proper title of the mainpage. However, when the form is passed to the database, the page ID is passed to the database. This isn't how I want it to work, I need it to pass on a slug to the database instead.
I understand that the code I'm using retrieves all of the fields in the database. How could I select just the Title field and the Slug field, and then in the form pass the Slug field to the database?
Cheers
You will have to change the Transformer used by EntityType, And it isnt the id being passed to the database it is the entity as the Transformer takes the id and looks up the entity in its list. So in your case it would be an instance of Shout\AdminBundle\Entity\Content
精彩评论