Gabriel Santos
Gabriel Santos

Reputation: 4974

CakePHP not autopopulating

Data from $this->EventoObreiro->find('all');:

Array (
    [0] => Array (
            [EventoObreiro] => Array (
                    [id] => 1
                    [evento_id] => 2
                    [obreiro_id] => 5
                )
        )
    [1] => Array (
            [EventoObreiro] => Array (
                    [id] => 2
                    [evento_id] => 2
                    [obreiro_id] => 3
                )
        )
)

HTML Form:

<?php echo $this->Form->create('EventoObreiro', array('url' => '/eventos/presenca/' . $evento['Evento']['id'])); ?>
    <?php if(count($obreiros) > 0) { ?>
        <?php foreach($obreiros as $k => $obreiro) { ?>
            <?php echo($obreiro['Usuario']['nome']); ?>
            <?php echo($this->Form->input('EventoObreiro.' . $k . '.obreiro_id', array('type' => 'hidden', 'value' => $obreiro['Obreiro']['id']))); ?>
            <?php echo($this->Form->input('EventoObreiro.' . $k . '.evento_id', array('type' => 'radio', 'legend' => false, 'options' => array('1' => 'Sim', '0' => 'Não')))); ?>
        <?php } ?>
    <?php } ?>

    <?php echo $form->button('Salvar presença', array('type' => 'submit', 'class' => 'button', 'name' => 'botaoAdicionar')); ?>
<?php $this->Form->end(); ?>

$obreiros are set from $this->set('obreiros', $this->Obreiro->find('all'));

But my form are not auto populated. How I can do this?

Upvotes: 0

Views: 48

Answers (1)

Cosmin P&#226;rvulescu
Cosmin P&#226;rvulescu

Reputation: 324

There can be a number of things wrong with this, it is not clear from your code but look into the following:

  1. Make sure that the information from $this->EventoObreiro->find('all'); is actually sent to the view. You can do this using <?php echo debug($obreiros); ?>. If it is not sent you should verify your controller code [maybe even edit your post and add it for clarity.]

  2. I don't see any Usuario in your Array so maybe try using $obreiro['EventoObreiro']['key'] instead of $obreiro['Usuario']['key']

Upvotes: 2

Related Questions