我用codeigniter做了一个购物车。
我在购物车中添加了几本书的详细信息。我想在不同的 div 中显示特定的购物车选项值。但我无法展示它。
我尝试了下面的代码,但是有了这个,我一次得到了所有的选项值。
请帮我。
控制器.php
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);
}
}
视图.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->cart->contents()) ;
输出(购物车中的 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) } }