我使用codeigniter制作了一个购物车。
我在购物车中添加了几本书的详细信息。我想在不同的div中显示特定的购物车选项值。但我无法证明这一点。
我尝试了下面的代码,但是这样我就可以立即获得所有选项值。
请帮帮我。
function add($id=0)
{
if($id>0)
{
$query = $this->Booksmodel->get($id);
$bid = $query['book_id'];
$qnty = $query['quantity'];
$price = $query['price'];
$title = $query['book_title'];
$covername ='Hard Cover';
$afname = $query['auth_firstname'];
$alname = $query['auth_lastname'];
$aname=$afname.' '.$alname;
$img = $query['img1'];
$data = array
(
'id' => $bid,
'qty' => $qnty,
'price' => $price,
'name' => $title,
'options' => array('aname' => $aname, 'covername' => $covername,'Bimg' => $img)
);
$this->cart->insert($data);
$this->load->view('cart/cart',$data);
}
}
view.php
---------------
----------------
<?php $i = 1; ?>
<?php foreach($this->cart->contents() as $items): ?>
<td> //i want to display here only the value of the a name
<?php foreach ($this->cart->product_options($items['rowid']) as $aname => $option_value): ?>
<?php echo $option_value; ?>
<?php endforeach; ?>
</td>
<?php $i++; ?>
<?php endforeach; ?>
-----------------
----------------
var_dump($ this-&gt; cart-&gt; contents());
OUTPUT(购物车中的1项):
array(1) { ["3705f19b9e71159a8b1a84079cfa8a3f"]=> array(7) { ["rowid"]=> string(32)
"3705f19b9e71159a8b1a84079cfa8a3f" ["id"]=> string(2) "17" ["qty"]=> string(1) "1" ["price"]=>
string(2) "46" ["name"]=> string(39) "Budhhiyoga Of the Gita And other Essays" ["options"]=>
array(3) { ["aname"]=> string(16) "Sri Anirvan" ["covername"]=> string(11)
"Hard Cover" ["Bimg"]=> string(13)
"DSC00a009.JPG" } ["subtotal"]=> int(46) } }
答案 0 :(得分:2)
更新
我想这次我把它钉了
<?php $i = 1; ?>
<?php foreach($this->cart->contents() as $item): ?>
<td> //i want to display here only the value of the a name
<?php echo $item['options']['covername']; ?>
</td>
<?php $i++; ?>
<?php endforeach; ?>