Saving id of a form select

0

I need to save the id of a select , but in my select , it is showing the name of the item, so in case I need to save in the database the id of this item. >

Form:

<?=$this->Form->create('Acomodacao');?>
                        <?= $this->Form->input('acomodacoes',array(
                            'type' => 'select',
                            'options' => $acomodacoes,
                            'class' => 'form-control',
                            'empty' => false
                            )); 
                        ?>
                        <?= $this->Form->input('semanas', array(
                            'options' => $semanas,
                            'empty' => 'Até',
                            'class' => 'form-control'
                        )); ?>

Controller:

$acomodacoes = $this->Navigation->find('list',array(
    'conditions' => array(
        'parent_id' => null,
    ),
    'fields' => array(
        'Navigation.id',
        'Navigation.nome',
    ),
));
$semanas = array();          
for ($i = 1; $i < 49; $i++) {
    $semanas[$i] = "$i semana" . ($i > 1 ? "s" : "");
}

The weeks are saved right, but the id in my database always stays equal to 0 because it is trying to save the name.

My form save looks like this:

if ($this->request->is('post')){
        $this->Acomodacao->save($this->request->data);
}
    
asked by anonymous 14.04.2015 / 22:17

0 answers