doumindang2416 2012-05-09 18:24
浏览 12
已采纳

CakePHP不能自动填充

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?

  • 写回答

1条回答 默认 最新

  • dotdx80642 2012-05-09 18:35
    关注

    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']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改