File tree 2 files changed +13
-4
lines changed
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,8 @@ class DefaultController extends Controller
12
12
public function entityChoicesAction (Request $ request )
13
13
{
14
14
$ myChoice = new MyChoice ();
15
- $ favColour = $ this ->getDoctrine ()->getRepository ('MCMDemoBundle:Colour ' )->find (4 );
16
- $ myChoice ->setFavColour ($ favColour );
17
15
18
- $ form = $ this ->createForm (new EntityChoiceType (), $ myChoice , array (
16
+ $ form = $ this ->createForm (new EntityChoiceType (3 ), $ myChoice , array (
19
17
'action ' => $ this ->generateUrl ('mcm_demo_entity_choice_form ' ),
20
18
'method ' => 'POST ' ,
21
19
));
Original file line number Diff line number Diff line change 9
9
10
10
class EntityChoiceType extends AbstractType
11
11
{
12
+ private $ myVar ;
13
+
14
+ public function __construct ($ myVar )
15
+ {
16
+ $ this ->myVar = $ myVar ;
17
+ }
18
+
12
19
public function buildForm (FormBuilderInterface $ builder , array $ options )
13
20
{
21
+ $ myModifier = $ this ->myVar ;
22
+
14
23
$ builder
15
24
->add ('favColour ' , 'entity ' , array (
16
25
'class ' => 'MCMDemoBundle:Colour ' ,
17
26
'property ' => 'name ' ,
18
- 'query_builder ' => function (EntityRepository $ er ) {
27
+ 'query_builder ' => function (EntityRepository $ er ) use ( $ myModifier ) {
19
28
return $ er ->createQueryBuilder ('c ' )
20
29
->orderBy ('c.name ' , 'DESC ' )
30
+ ->where ('c.id >= :myModifier ' )
31
+ ->setParameter ('myModifier ' , $ myModifier )
21
32
;
22
33
},
23
34
))
You can’t perform that action at this time.
0 commit comments