2013-02-24 150 views
0

我希望在cakephp的頁面上的每個表格行下都有多個表單。我不知道如何更改輸入名稱以允許這樣做。cakephp多種形式

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

回答

0

CakePHP將生成正常的表格,只要它們是唯一命名的。你可能會考慮追加會員ID到形式的名稱:

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

你可以使用這個(或您想任何其他方法),使形式獨特。您也可能會遇到非唯一字段名稱的問題。在這種情況下,如果來自同一個控制器,則使用類似的技巧在所有形式和字段中都有唯一的字段名稱。

+0

我想到了這一點,但我缺少Point1s控制器 – 2013-02-25 17:46:58

+0

如果命名錶單不同,你將不得不手動指定控制器。 (''成員'] ['id'],數組('controller'=>'myController','action'=>'add' )); ?>' – swiecki 2013-02-27 03:40:35