Input listing cakephp query result

Asked

Viewed 74 times

1

Hello, I’m trying to list a result of a query of my controller in an input, but it is returning zero, but when I give print_r, it returns me all array, what’s wrong?

Controller:

public function add() {
    if ($this->request->is('post')) {
        if ($this->Foto->save($this->request->data)) {
            $this->Session->setFlash('Recipe Saved!');
            $this->render('add');
        }
    }
    $acomodacoes = $this->Navigation->find('list');
    $this->set('acomodacoes',$acomodacoes);
    print_r($acomodacoes); // estou dando esse print_r só para ver se realmente existe um array
}

My form:

<?= $this->Form->create('Galeria.Foto',array('type' => 'file')); ?>
<fieldset>            
    <legend><?= __('Adicionar Galeria de fotos'); ?></legend>
     <strong> Hot? </strong>
    <?=  $this->Form->checkbox('hot', array('value' => 1)); ?>
    <?=  $this->Form->input('acomodacoes',array('class' => 'form-control')); ?>
    <?=  $this->Form->input('titulo',array('class' => 'form-control')); ?>
    <?=  $this->Form->input('descricao',array('class' => 'form-control')); ?>                
    <?=  $this->Form->input('Imagem', array('type' => 'file')); ?>

</fieldset>
<?php echo $this->Form->end(__('Submit',array('class' => 'form-control'))); ?>

1 answer

1

It is necessary to inform the array $accommodating in the input related. And being several options, you need the property type and options:

$this->Form->input('acomodacoes', array(
    'class' => 'form-control',
    'type' => 'select',
    'options' => $acomodacoes)
);

For the options, you will have as value the id item, and case your Model has defined the displayField, will be this the displayed text.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.