我想做的是为用户提供一种从库存中结帐多种产品的方法。
我的产品索引页面(列出所有要签出的可用产品)如下所示:
<?php echo $this->Form->create('multi');?>
<?php foreach ($products as $product): ?>
<tr class="hovertable">
//All the fields go here
<td style="cursor: default">
<?php echo $this->Html->link($this->Html->image('tr/Checkouts_Add.png') . " " . __('Checkout'), array('controller' => 'Checkouts','action' => 'add', $product['Product']['id']), array('escape' => false, 'class' => 'button')); ?>
<?php echo $this->Html->link($this->Html->image('tr/Edit.png'), array('action' => 'edit', $product['Product']['id']), array('escape' => false)); ?>
<?php echo $this->Form->postLink($this->Html->image('tr/Delete.png'), array('action' => 'delete', $product['Product']['id']), array('escape' => false), __('Are you sure you want to delete # %s?', $product['Product']['id'])); ?>
<?php echo $this->Form->input('Product.id.'.$product['Product']['id'] ,
array('label' => false,
'type' => 'checkbox',
'id'=>'listing_'.$product['Product']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
<?php echo $this->Form->submit(__('Submit'));?>
然后在我的结帐控制器中,我添加了一个新功能来结帐多个项目,我希望这个表单由检查的产品填充
public function multi($count = 1) {
if($this->request->is('post')) {
foreach($this->request->data['Checkout'] as $data) {
//Do not forget this line. you need to create new model for saving each time.
if ($this->request->isPost()) {
$this->Checkout->create();
$this->Checkout->save($data);
} else {
$this->request->data['Checkout']['product_id'] = $productId;
}
}
$this->redirect(array('action' => 'index'));
}
$products = $this->Checkout->Product->find('list');
$users = $this->Checkout->User->find('list');
$this->set(compact('products', 'users'));
$this->set('count', $count);
}
如您所见,我尝试添加我认为可能有效的帽子,但产品索引页面中的提交按钮没有任何作用。任何帮助将不胜感激!