# CodeIgniter 显示购物车

**URL:** <https://www.isharkfly.com/t/codeigniter/4229>\
**Category:** PHP\
**Created:** [January 7, 2014, 3:31am UTC](https://www.isharkfly.com/t/codeigniter/4229 "2014-01-07T03:31:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 7, 2014, 3:31am UTC](https://www.isharkfly.com/t/codeigniter/4229/1 "2014-01-07T03:31:29Z")

</div>

为了显示购物车的数据，你得创建一个 视图文件，它的代码类似于下面这个。

请注意这个范例使用了表单辅助函数。[code]\<?php echo form\_open('path/to/controller/update/function'); ?\>

\<?php $i = 1; ?\> \<?php foreach ($this-\>cart-\>contents() as $items): ?\> \<?php echo form\_hidden($i.'[rowid]', $items['rowid']); ?\> \<?php $i++; ?\> \<?php endforeach; ?\>

| QTY | Item Description | Item Price | Sub-Total |
| --- | --- | --- | --- |
| \<?php echo form\_input(array('name' =\> $i.'[qty]', 'value' =\> $items['qty'], 'maxlength' =\> '3', 'size' =\> '5')); ?\> | \<?php echo $items['name']; ?\> \<?php if ($this-\>cart-\>has\_options($items['rowid']) == TRUE): ?\>

```
<p>
 <?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
   
  <strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
       
 <?php endforeach; ?>
</p>

```

 \<?php endif; ?\> | \<?php echo $this-\>cart-\>format\_number($items['price']); ?\> | $\<?php echo $this-\>cart-\>format\_number($items['subtotal']); ?\> |
| | **Total** | $\<?php echo $this-\>cart-\>format\_number($this-\>cart-\>total()); ?\> |

\<?php echo form\_submit('', 'Update your Cart'); ?\>

[/code]文章来源：[url]http://cwiki.ossez.com/pages/viewpage.action?pageId=2392141[/url]
