Hola, creo que hablas espaƱol.
En realidad funciona como es de esperarse. Llamas a la accion pasando el
id de la empresa que la accion lo utiliza para obtener los datos pero
luego al generar la vista y enviar el formulario es logico que se pierda
el id de la empresa ya que no figura en ningun lado y vuelves a mandar
al controlador solo los datos del formulario... Deberias hacer algo asi:
Agregar al formulario el siguiente campo oculto con el id de la empresa:
<?php echo $form->create('Local',array('action'=>'agregar'));?>
<input type="hidden" name="*data[Empresa][id]*" value="<?php echo
$empresa[Empresa][id]; ?>" />
...
...
Y luego en la accion usar:
if (!empty($this->data)) {
if ($this->Local->save($this->data)) {
$this->Session->setFlash('Un nuevo local ha sido agregado al
sistema.');
$this->redirect(array('action' => 'lista',
*$this->data[Empresa][id]*));
}
}
Espero que te sirva.
Frannie escribió:
> Hello. I want to thank you in advance for your time.
> I am trying to make a form and the action that uses has a parameter,
> but when I submit the form the parameter disappears....
>
> *********this is my form:
>
> <?php echo $form->create('Local',array('action'=>'agregar'));?>
> <table>
> <tr>
> <th>Nombre</th>
> <td><?php echo $form->input('Local.nombre',
> array('label'=>'')); ?></
> td>
> </tr>
> <tr>
> <th>Tipo</th>
> <td><?php echo $form->input('Local.tipo', array
> ('label'=>'','type'=>'select')); ?></td>
> </tr>
> <tr>
> <th>Región</th>
> <td><?php echo $form->input('region',
> array('label'=>'','options'=>
> $regiones)); ?></td>
> </tr>
> <tr>
> <th>Comuna</th>
> <td><?php echo $form->input('Local.comuna_id', array
> ('label'=>'','type'=>'select')); ?></td>
> </tr>
> <tr>
> <th>Dirección</th>
> <td><?php echo $form->input('Local.direccion',
> array('label'=>'')); ?
>
>> </td>
>>
> </tr>
> <tr>
> <th>Teléfono</th>
> <td><?php echo $form->input('Local.telefono',
> array('label'=>'')); ?
>
>> </td>
>>
> </tr>
> <tr>
> <th>E-mail</th>
> <td><?php echo $form->input('Local.email', array('label'=>''));
> ?></
> td>
> </tr>
> <tr>
> <th>Patente</th>
> <td><?php echo $form->input('Local.patente',
> array('label'=>'')); ?
>
>> </td>
>>
> </tr>
> </table>
> <?php echo $form->end('Guardar');?>
>
> ***********this is the action:
> function agregar($empresa_id){
>
> $this->set('CSS','estilo');
> $this->set('empresas_list',$this->Nav->showEmpresas());
> $this->set('empresa',$this->Empresa->find('first', array
> ('conditions' => array('Empresa.id' => $empresa_id))));
>
> $this->set('comunas', $this->Local->Comuna->find('list'));
> $this->set('regiones',
> $this->Local->Comuna->Region->find('list'));
> $this->set('tipos', $this->Local->Catalogo->find('list', array
> ('conditions'=> array('Catalogo.grupo'=>'tipo_local'))));
>
> if (!empty($this->data)) {
> if ($this->Local->save($this->data)) {
> $this->Session->setFlash('Un nuevo local ha
> sido agregado al
> sistema.');
> $this->redirect(array('action' => 'lista',
> $empresa_id));
> }
> }
> }
>
> I load the view with an url like this: localhost/myroot/mycontroller/
> agregar/1
> then I fill the fields of the form and I submit, and then I lose my
> parameter. Does anybody know why this could be?
> I'm sorry, english is not my first language, if you have any questions
> about my problem just tell me.
> I really will appreciate your help.
>
> Francisca.
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---