Skip to content

Commit a72fde8

Browse files
committed
modify the query
1 parent ea613d5 commit a72fde8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/MCM/DemoBundle/Controller/DefaultController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ class DefaultController extends Controller
1212
public function entityChoicesAction(Request $request)
1313
{
1414
$myChoice = new MyChoice();
15-
$favColour = $this->getDoctrine()->getRepository('MCMDemoBundle:Colour')->find(4);
16-
$myChoice->setFavColour($favColour);
1715

18-
$form = $this->createForm(new EntityChoiceType(), $myChoice, array(
16+
$form = $this->createForm(new EntityChoiceType(3), $myChoice, array(
1917
'action' => $this->generateUrl('mcm_demo_entity_choice_form'),
2018
'method' => 'POST',
2119
));

src/MCM/DemoBundle/Form/Type/EntityChoiceType.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,26 @@
99

1010
class EntityChoiceType extends AbstractType
1111
{
12+
private $myVar;
13+
14+
public function __construct($myVar)
15+
{
16+
$this->myVar = $myVar;
17+
}
18+
1219
public function buildForm(FormBuilderInterface $builder, array $options)
1320
{
21+
$myModifier = $this->myVar;
22+
1423
$builder
1524
->add('favColour', 'entity', array(
1625
'class' => 'MCMDemoBundle:Colour',
1726
'property' => 'name',
18-
'query_builder' => function (EntityRepository $er) {
27+
'query_builder' => function (EntityRepository $er) use ($myModifier) {
1928
return $er->createQueryBuilder('c')
2029
->orderBy('c.name', 'DESC')
30+
->where('c.id >= :myModifier')
31+
->setParameter('myModifier', $myModifier)
2132
;
2233
},
2334
))

0 commit comments

Comments
 (0)