duanchi19820419 2013-02-24 00:19
浏览 30
已采纳

cakephp多种形式

I wish to have have multiple forms under each table row on a page with cakephp. I am not sure how to change the input names to allow this.

    <table cellpadding="0" cellspacing="0">
    <tr>
            <th><?php echo $this->Paginator->sort('id'); ?></th>
            <th><?php echo $this->Paginator->sort('member_no'); ?></th>
            <th><?php echo $this->Paginator->sort('first_name'); ?></th>
            <th><?php echo $this->Paginator->sort('last_name'); ?></th>
            <th><?php echo $this->Paginator->sort('total_points'); ?></th>
            <th><?php echo $this->Paginator->sort('date_joined'); ?></th>
            <th class="actions"><?php echo __('Actions'); ?></th>
    </tr>
    <?php foreach ($members as $member): ?>
    <tr>
        <td><?php echo h($member['Member']['id']); ?>&nbsp;</td>
        <td><?php echo h($member['Member']['member_no']); ?>&nbsp;</td>
        <td><?php echo h($member['Member']['first_name']); ?>&nbsp;</td>
        <td><?php echo h($member['Member']['last_name']); ?>&nbsp;</td>
        <td><?php echo h($member['Member']['total_points']); ?>&nbsp;</td>
        <td><?php echo h($member['Member']['date_joined']); ?>&nbsp;</td>
        <td class="actions">
            <?php echo $this->Html->link(__('View'), array('action' => 'view', $member['Member']['id'])); ?>
            <?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $member['Member']['id'])); ?>
            <?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $member['Member']['id']), null, __('Are you sure you want to delete # %s?', $member['Member']['id'])); ?>
        </td>
    </tr>
    <tr>
        /// This is the form for each record
        <td>
            <?php echo $this->Form->create('Point', array('action' => 'add')); ?>
                <fieldset>
                    <legend><?php echo __('Add Point'); ?></legend>
                <?php
                    echo $this->Form->input('member_id',array('type'=>'hidden', 'value'=>$member['Member']['id']));
                    echo $this->Form->input('points');
                ?>
                </fieldset>
            <?php echo $this->Form->end(__('Submit')); ?>
        </td>
    </tr>
<?php endforeach; ?>
    </table>
  • 写回答

1条回答 默认 最新

  • dougu0824 2013-02-24 01:31
    关注

    CakePHP will produce the forms as normal, as long as they are uniquely named. You might consider appending the member id onto the name of the form:

    <?php echo $this->Form->create('Point'.$member['Member']['id'], array('action' => 'add')); ?>
    

    You can use this (or any other method you'd like) to make the forms unique. You may also have a problem with non-unique field names. In that case, use a similar trick to have all unique field names in both forms and fields if they are from the same controller.

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

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教