# CakePhp 3 change display value of a variable

**URL:** <https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518>\
**Category:** Need Help\
**Created:** [June 9, 2016, 10:03pm UTC](https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518 "2016-06-09T22:03:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davicosk8](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@davicosk8](https://discourse.cakephp.org/u/davicosk8)\
**Post date:** [June 9, 2016, 10:03pm UTC](https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518/1 "2016-06-09T22:03:26Z")

</div>

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):

![](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex029/uploads/cakephp/original/1X/8c370e543e2e1edd8c6139b68fde33d7ea342974.png)

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]);`

![](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex029/uploads/cakephp/original/1X/e32967709225a97449170355febd101744502a01.png)

Please Help ME!

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [June 10, 2016, 2:51am UTC](https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518/2 "2016-06-10T02:51:16Z")

</div>

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

```auto
// 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]);

```

---

<div class="post-metadata">

**Author:** ![davicosk8](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@davicosk8](https://discourse.cakephp.org/u/davicosk8)\
**Post date:** [June 10, 2016, 12:39pm UTC](https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518/3 "2016-06-10T12:39:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeremyharris](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jeremyharris/32/66_2.png) [@jeremyharris](https://discourse.cakephp.org/u/jeremyharris)\
**Post date:** [June 10, 2016, 3:39pm UTC](https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518/4 "2016-06-10T15:39:05Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![davicosk8](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@davicosk8](https://discourse.cakephp.org/u/davicosk8)\
**Post date:** [June 20, 2016, 7:46pm UTC](https://discourse.cakephp.org/t/cakephp-3-change-display-value-of-a-variable/518/5 "2016-06-20T19:46:37Z")

</div>

Thanks! it really helped me, 👍
