Save a variable into controller
I have this form first:
<form action="{{path('entrenamiento_new')}}" method="post" accept-charset="utf-8">
<fieldset>
<legend> Seleccione </legend>
<p><label> <input type="radio" name="tipoentrenamiento_id" value="1" checked="true"> Tipo X7 </label></p>
<p><label> <input 开发者_Go百科type="radio" name="tipoentrenamiento_id" value="0"> Otro</label></p>
</fieldset>
<p><input type="submit" value="Continuar →"></p>
</form>
And this is the routing:
entrenamiento_new:
pattern: entrenamiento/new
defaults: {_controller: GitekUdaBundle:Entrenamiento:new}
requirements:
_method: POST
id: \d+
Now I have a post variable tipoentrenamiento_id witch I want to save into Formacion entity when I process the formacion/new controller.
How can I save this data in the createAction?? My Formacion entity has a tipoentrenamiento_id field already.
If you only need to store a Post value in the controller you can use
$entity->setXxxxxx('value) for that where Xxxxx is the name of your field in the Entity.
For example, assuming your entity field name is "tipoentenamiento_id", your controller must be:
public function newAction()
{
$request = $this->getRequest();
//Get your POST value
$foo = $request->request->get('tipoentrenamiento_id');
$entrenamiento = new Entrenamiento();
$entrenamiento->setTipoentrenamientoId($foo);
$form = $this->createForm(new EntrenamientoType(), $entrenamiento);
return array(
'entrenamiento' => $entrenamiento,
'form' => $form->createView()
);
}
精彩评论