I created a custom form type like this:
class PositioningFlashType extends AbstractType
{
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'game' => new Game()
));
}
public function getParent()
{
return 'form';
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return 'positioning_flash';
}
}
And in another form (GameType
) type I use it like this:
$builder
->add('flash', new PositioningFlashType(), array(
'mapped' => false,
'game' => $options['game']
))
And inside the controller I want to create the whole form:
private function createEditForm(Game $entity)
{
$form = $this->createForm(new GameType(), $entity, array(
'action' => $this->generateUrl('game_update', array('id' => $entity->getId())),
'method' => 'PUT',
'edit' => true,
'game' => $entity
));
$form->add('submit', 'submit', array('label' => 'Speichern'));
return $form;
}
So basically, all I want to do is to pass-through the Game
instance to the PositioningFlashType
and inside it's template I want to access this game
instance like this:
value="{{ asset('data/swf/backendtool.swf') }}?game={{ game.id }}
But symfony throws an error, saying that the variable game
is not defined.
What is the correct way to pass-through a variable from the controller to a nested FormType?
{{ form.game.id }}
? – Electrophorus