为什么在我的帖子里只有一个项目?CakePHP2.x
我的视线中有一张桌子。这张桌子很整洁。我需要将表中的所有项目发送到我的控制器。我创建表单,但他只发送了一项,最后一项。。。 这是我的桌子:为什么在我的帖子里只有一个项目?CakePHP2.x,php,cakephp,Php,Cakephp,我的视线中有一张桌子。这张桌子很整洁。我需要将表中的所有项目发送到我的控制器。我创建表单,但他只发送了一项,最后一项。。。 这是我的桌子: <?php echo $this->Form->create('Goodsandoffer');?> <table id="GoodSandOffersTable" class="display" cellspacing="0" width="100%"> <thead><tr&g
<?php echo $this->Form->create('Goodsandoffer');?>
<table id="GoodSandOffersTable" class="display" cellspacing="0" width="100%">
<thead><tr>
<th><?php echo $this->Paginator->sort('id','ID'); ?></th>
<th><?php echo $this->Paginator->sort('nazwa','Nazwa'); ?></th>
<th><?php echo $this->Paginator->sort('kodKreskowy','Kod EAN'); ?></th>
<th><?php echo $this->Paginator->sort('cenaSprzedazyBrutto','Cena sprzedaży brutto'); ?></th>
<th>Cena Promocyjna</th>
<th>Akcja</th>
</tr>
</thead>
<tbody>
<?php $x =0;?>
<?php foreach ($goods as $good): ?>
<tr>
<td><?php echo h($goodID= $good['Good']['id']);?></td>
<td><?php echo h($good['Good']['nazwa']);?></td>
<td><?php echo h($good['Good']['kodKreskowy']);?></td>
<td><?php echo h($good['Good']['cenaSprzedazyBrutto']);?></td>
<?php echo $this->Form->input('promotionaloffer_id',array("default"=>$prom['Promotionaloffer']['id'],'type'=>'hidden'));?>
<?php echo $this->Form->input('good_id',array("default"=>$good['Good']['id'],'type'=>'hidden'));?>
<td><?php echo $this->Form->input('cenaPromocyjna', array('id' => 'cenaPromocyjna'.$x));?></td>
</tr>
<?php $x = $x + 1 ;?>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $this->Form->end(__('Dodaj')); ?>
当我调试时,我得到了这个:
\app\Controller\GoodsandoffersController.php (line 110)
array(
'Goodsandoffer' => array(
'promotionaloffer_id' => '3',
'good_id' => '20',
'cenaPromocyjna' => '3'
)
)
在数组中,我只有表中的最后一项。我需要一切。我做错了什么?我自己对CakePHP不熟悉,但表行中的所有字段似乎都有相同的名称(promotionaloffer\u id、good\u id、cenaPromocyjna):
为了接收所有值,您需要使用如下数组键指示它们:
<?php echo $this->Form->input('promotionaloffer_id['.$good['Good']['id'].']',array("default"=>$prom['Promotionaloffer']['id'],'type'=>'hidden'));?>
<?php echo $this->Form->input('good_id['.$good['Good']['id'].']',array("default"=>$good['Good']['id'],'type'=>'hidden'));?>
<td><?php echo $this->Form->input('cenaPromocyjna['.$good['Good']['id'].']', array('id' => 'cenaPromocyjna'.$x));?></td>
这将导致输入名称如下
- promotionaloffer\u id[0],good\u id[0],cenaPromocyjna[0]
- 促销优惠id[1],良好id[1],cenaPromocyjna[1]
- 促销优惠id[x]、良好id[x]、cenaPromocyjna[x]
其中x是good-id。您是否查看了生成的HTML?从外观上看,您的字段名似乎都具有相同的名称。
<?php echo $this->Form->input('promotionaloffer_id',array("default"=>$prom['Promotionaloffer']['id'],'type'=>'hidden'));?>
<?php echo $this->Form->input('good_id',array("default"=>$good['Good']['id'],'type'=>'hidden'));?>
<td><?php echo $this->Form->input('cenaPromocyjna', array('id' => 'cenaPromocyjna'.$x));?></td>
<?php echo $this->Form->input('promotionaloffer_id['.$good['Good']['id'].']',array("default"=>$prom['Promotionaloffer']['id'],'type'=>'hidden'));?>
<?php echo $this->Form->input('good_id['.$good['Good']['id'].']',array("default"=>$good['Good']['id'],'type'=>'hidden'));?>
<td><?php echo $this->Form->input('cenaPromocyjna['.$good['Good']['id'].']', array('id' => 'cenaPromocyjna'.$x));?></td>