Set input data like id from the called model

I need some help.

I am in View from Seleccion Model.
I did create a button for Add for Antecedentes Model (in the seleccion view).
Antecedentes Model has Seleccion_id input.

I want to set the value of Antecendete Seleccion_id = Seleccion id wich I pickup the button.


For example this way:
Add a link in your Seleccion View, where you pass one (or more params):

<?= $this->Html->link(__('Add Antecedentes'), ['controller'=>'AntecedentesController','action' => 'add','?'=>["foo" => "bar",'seleccion_id'=>$seleccion->id],"#" => "first"], ['class' => 'side-nav-item']) ?>

After clicking on the link you can check in your AntecedentesController in the add-action which values were passed:

Thanks for your answer.
In the URL I can see the seleccione_id=2
Now how I do se it in the add view or controller

echo $this->Form->control(‘seleccione_id’, [‘default’ => $this->request->???[‘seleccione_id’]]);


Is this in your add or edit page? In the edit, you shouldn’t need to set a default at all, as it should be there automatically from the entity you’re editing. In the add, do you want to set a default?

Yes is the add action for seleccionAntecendestes that was called from the view of a record in seleccion.
seleccionAntecedentes stores the seleccion_id, that is what i want to store deffault.

Ah, gotcha. In your controller, you can use something like
$seleccione_id = $this->request->getQuery('seleccione_id');
to get the query parameter, and then
to send that variable to the view. Then just 'default' => $seleccione_id.

Note that if you don’t want them to be able to change the value, then a hidden field instead of an input control would be the way to go.

Still mising something.

The link in seleccione view

<?= $this->Html->image("add.png", ['url' => ['controller' => 'SeleccionAntecedentes','action' => 'add','?'=>['seleccione_id'=>$seleccione->id]]]) ?><?= __('ANTECEDENTES') ?>

In seleccioneAntecedente add controller, the value in captured correctly, I echo it and it’s ok, but the value is not setting for storing in db

$seleccionAntecedente = $this->SeleccionAntecedentes->patchEntity($seleccionAntecedente, $this->request->getData());
$seleccione_id = $this->request->getQuery(‘seleccione_id’);
if ($this->SeleccionAntecedentes->save($seleccionAntecedente)) {
$this->Flash->success((‘The seleccion antecedente has been saved.’.$seleccione_id));
return $this->redirect([‘controller’ => ‘selecciones’, ‘action’ => ‘view’, $this->request->getData(‘seleccione_id’)]);
(‘The seleccion antecedente could not be saved. Please, try again.’));

You’ve skipped some code from your controller here. There’s presumably a bit that checks if it’s a post, and does all of this stuff only in that case? You want the getQuery and set lines to be before that, so they happen when the empty form is loaded, not just when it’s posted.

Thanks so much for all your help and patience.
You where right just put the code befote de post check.
Thanks again.