Hey Guys. I am working on a form for adding an museum object on database. I have a field where I should select the object donator, wich belongs to another table. The way I did it, I can already select the donators by name on the form, but then this happens:
Well, I want / need to remove these numbers from my select view, but can´t figure out how I do that.
Here is my controller function add code:
public function add()
{
$connection = ConnectionManager::get('default');
$objeto = $this->Objeto->newEntity();
if ($this->request->is('post')) {
$objeto = $this->Objeto->patchEntity($objeto, $this->request->data);
if ($this->Objeto->save($objeto)) {
$this->Flash->success(__('The objeto has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The objeto could not be saved. Please, try again.'));
}
$this->set(compact('objeto'));
$this->set('_serialize', ['objeto']);
$this->loadModel('Doador');
$listaDoadores = $this->Doador->find('all', array(
'fields' => array('Doador.nome')));
$doadores = $connection->execute($listaDoadores)->fetchAll('assoc');
if ($this->request->is('requested')) { //Se for requisição de outra view/element:
return $doadores;
} else { //Senão envia para a view padrão
$this->set('doadores', $doadores);
} ?>
<?php
print_r($doadores);
}
And this is my View so far:
<?= $this->Form->create($objeto) ?>
<fieldset>
<legend><?= __('Add Objeto') ?></legend>
<?php
echo $this->Form->input('nome');
echo $this->Form->input('nomeTecnico');
echo $this->Form->input('tipo');
echo $this->Form->input('aquisicao');
echo $this->Form->input('procedencia');
echo $this->Form->input('dataDoacao', ['empty' => true]);
echo $this->Form->input('dataObjeto');
echo $this->Form->input('forma');
echo $this->Form->input('cor');
echo $this->Form->textarea('detalhamento', ['placeholder' => 'Detalhamento do Objeto']);
echo $this->Form->input('dimensao_iddimensao');
echo $this->Form->input('foto_idfoto');
echo $this->Form->input('inscricao_idinscricao');
echo $this->Form->input('doador_id', ['type' => 'select', 'options' => $doadores]);
echo $this->Form->input('fabricante');
echo $this->Form->input('historico');
echo $this->Form->textarea('etiqueta_exposicao', ['placeholder' => 'Descrição da etiqueta de Exposição']);
echo $this->Form->input('emExposição');
echo $this->Form->input('condicao',['type' => 'select', 'options' => ['nome1' => 'Perfeito Estado', 'nome2' => 'Necessita Intervenção']]);
echo $this->Form->input('condicao');
echo $this->Form->input('catalogador');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
Can Anyone Help me see realize what am I doing wrong?
Thanks very much in advance!