Reputation: 463
I have find more answer about this, but return error "The option "prova" does not exist "
I make this
in defaultcontroller.php
$form = $this->createForm(new ProvinciaType(), $provincia, array('prova' => 'ciao'));
in ProvinciaType.php
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name', 'entity', array(
'class' => 'AcmeIndexBundle:Provincia',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.name', 'ASC');
},'empty_value' => $options['prova']
));
}
but not work why?
Upvotes: 0
Views: 2247
Reputation: 10404
Simply pass it to the constructor :
$this->createForm(new ProvinciaType($options), $provincia)
And use it in the form :
public function __construct($options) {
$this->options = $options;
}
Then use this in buildForm :
$options = $this->options;
....
function(EntityRepository $er) use ($options)
...
},'empty_value' => $options['prova']
....
Upvotes: 5