i’m having a real bad time trying to do this, please someone helpme!
i have this add view where i want to have 2 selectors, eveerytime a select something in one selector, the second selector must update its data.
this is my database and how is it displaying right now
every Empresas hasMany Sucursales
Im trying to this in Ofertas add, so i have this in my controller
public function add()
{
$tblOferta = $this->TblOfertas->newEntity();
if ($this->request->is('post')) {
$tblOferta = $this->TblOfertas->patchEntity($tblOferta, $this->request->data);
if ($this->TblOfertas->save($tblOferta)) {
$this->Flash->success(__('The tbl oferta has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The tbl oferta could not be saved. Please, try again.'));
}
}
$tblCategorias = $this->TblOfertas->TblCategorias->find('list');
$tblSucursales = $this->TblOfertas->TblSucursales->find('list');
$tblEmpresas = $this->TblOfertas->TblSucursales->TblEmpresas->find('list');
$this->set('tblCategorias', $tblCategorias);
$this->set('tblSucursales', $tblSucursales);
$this->set('tblEmpresas', $tblEmpresas);
$this->set('tblOferta', $tblOferta);
$this->set('_serialize', ['tblOferta']);
}
and this in my add.ctp view
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('List Tbl Ofertas'), ['action' => 'index']) ?></li>
</ul>
</nav>
<div class="tblOfertas form large-9 medium-8 columns content">
<?= $this->Form->create($tblOferta) ?>
<fieldset>
<legend><?= __('Añadir Oferta') ?></legend>
<?php
echo $this->Form->input('nombre');
echo $this->Form->input('descripcion');
echo $this->Form->input('nombre_imagen');
echo $this->Form->input('fecha_creacion');
echo $this->Form->input('estado_activa');
echo $this->Form->input('fecha_inicio');
echo $this->Form->input('fecha_fin');
echo $this->Form->input('duracion_dias');
echo $this->Form->input('nombre_encargado');
echo $this->Form->input('telefono_encargado');
echo $this->Form->input('email_encargado');
echo $this->Form->input('tbl_categoria_id', ['options' => $tblCategorias]);
echo $this->Form->input('empresas', ['options' => $tblEmpresas]);
echo $this->Form->input('tbl_sucursales._ids', ['options' => $tblSucursales]);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
every time a select an Empresa, Sucursales must update its data, “every Empresa hasMany sucursales”