CakePhp 3 change display value of a variable

i’ve been traying to change the display value of a variable sent by the controller, but can’t figure it out how,

this is in my controller

    $tblSucursales = $this->TblOfertas->TblSucursales->find('all')->contain('TblEmpresas');
    $this->set('tblSucursales', $tblSucursales);

that is in an ADD function, here is full code:

 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('all');
        $tblSucursales = $this->TblOfertas->TblSucursales->find('all')->contain('TblEmpresas');
        $this->set('tblSucursales', $tblSucursales);
        $this->set('tblCategorias', $tblCategorias);
        $this->set('tblOferta', $tblOferta);
        $this->set('_serialize', ['tblOferta']);
    }

if i debug $tblSucursales it works excellent, all data is there (every tblSucursal hasOne tblEmpresa):

now, in my add.ctp i want to show tblSucursal.nombre concatenated tbl.Sucursal.tblEmpresa.nombre

i’ve tryed many ways but always getting the same result, error. i can’t even get the name attribute of tblSucursales

echo $this->Form->input('tbl_sucursales._ids', ['options' => $tblSucursales.nombre]);

this is my full code of add.ctp

<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>
        <h2></h2>
        <?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('tbl_sucursales._ids', ['options' => $tblSucursales.nombre]);
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>

this is how it looks like if a just put raw $tblSucursales

echo $this->Form->input('tbl_sucursales._ids', ['options' => $tblSucursales]);

Please Help ME!

I recomend you load Empresas in a separate variable, and using the list finder

// In the controller, add action
$tblSucursales = $this->loadModel('TblEmpresas')->find('list');
$this->set('tblSucursales');
// in the template
echo $this->Form->input('tbl_sucursales._ids', ['options' => $tblSucursales]);

thanks for your help!, i’ll try to do that way.

but how can i get the attribute if i use the finder ‘all’, and display it on the view.

i’ve try all of this:

tblSucursales.nombre;
tblSucursales-> nombre;

i think this is cakephp 2.x convention

tblSucursales[nombre];

any comment will be helpfull.

It would be $tblSucursale->nombre to access the property. Since you’re using find('all') it will return be an array of entities (notice the array items in the debug) when you iterate through them, so something like this in the view:

foreach ($tblSucursales as $tblSucursale) {
  echo $tblSucursale->nombre;
  // nombre on this entity's tbl_empresa record
  echo $tblSucursale->tbl_empresa->nombre;
}

Thanks! it really helped me, :+1: